Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2016 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  import copy 
  27  from numpy import array, asarray, average, exp, median, inf, isnan, linspace, log, std, sum, zeros 
  28  from minfx.generic import generic_minimise 
  29  from random import gauss 
  30  import re, math 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_FULL, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from specific_analyses.relax_disp.checks import check_missing_r1 
  46  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  47  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  48  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  49  from specific_analyses.relax_disp.model import models_info, nesting_param 
  50  from specific_analyses.relax_disp.parameters import linear_constraints 
  51  from status import Status; status = Status() 
  52  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  53  from test_suite.system_tests.base_classes import SystemTestCase 
  54   
  55   
56 -class Relax_disp(SystemTestCase):
57 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 58
59 - def __init__(self, methodName='runTest'):
60 """Skip certain tests if the C modules are non-functional. 61 62 @keyword methodName: The name of the test. 63 @type methodName: str 64 """ 65 66 # Execute the base class method. 67 super(Relax_disp, self).__init__(methodName) 68 69 # Tests to skip. 70 blacklist = [ 71 'test_m61b_data_to_m61b' 72 ] 73 if methodName in blacklist: 74 status.skipped_tests.append([methodName, None, self._skip_type]) 75 76 # Missing module. 77 if not dep_check.C_module_exp_fn: 78 # The list of tests to skip. 79 to_skip = [ 80 "test_bug_atul_srivastava", 81 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 82 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 83 "test_estimate_r2eff_err", 84 "test_estimate_r2eff_err_auto", 85 "test_estimate_r2eff_err_methods", 86 "test_finite_value", 87 "test_exp_fit", 88 "test_m61_exp_data_to_m61", 89 "test_r1rho_kjaergaard_auto", 90 "test_r1rho_kjaergaard_auto_check_graphs", 91 "test_r1rho_kjaergaard_man", 92 "test_r1rho_kjaergaard_missing_r1", 93 "test_value_write_calc_rotating_frame_params_auto_analysis" 94 ] 95 96 # Store in the status object. 97 if methodName in to_skip: 98 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 99 100 # If not scipy.optimize.leastsq. 101 if not dep_check.scipy_module: 102 # The list of tests to skip. 103 to_skip = [ 104 "test_estimate_r2eff_err_methods" 105 ] 106 107 # Store in the status object. 108 if methodName in to_skip: 109 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 110 111 # If not NMRPipe showApod program in PATH. 112 if not dep_check.showApod_software: 113 # The list of tests to skip. 114 to_skip = [ 115 "test_show_apod_extract", 116 "test_show_apod_rmsd", 117 "test_show_apod_rmsd_to_file", 118 "test_show_apod_rmsd_dir_to_files" 119 ] 120 121 # Store in the status object. 122 if methodName in to_skip: 123 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 124 125 # If not matplotlib module 126 if not dep_check.matplotlib_module: 127 # The list of tests to skip. 128 to_skip = [ 129 "test_repeat_cpmg" 130 ] 131 132 # Store in the status object. 133 if methodName in to_skip: 134 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
135 136
137 - def setUp(self):
138 """Set up for all the functional tests.""" 139 140 # Create the data pipe. 141 self.interpreter.pipe.create('relax_disp', 'relax_disp') 142 143 # Create a temporary directory for dumping files. 144 ds.tmpdir = mkdtemp() 145 self.tmpdir = ds.tmpdir
146 147
148 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
149 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 150 151 @keyword folder: The name of the folder for the test data. 152 @type folder: str 153 @keyword model_analyse: The name of the model which will be tested. 154 @type model_analyse: str 155 """ 156 157 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 158 159 # Data. 160 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 161 162 ## Experiments 163 # Exp 1 164 sfrq_1 = 500.0*1E6 165 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 166 time_T2_1 = 0.05 167 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 168 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 169 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 170 r2eff_errs_1 = [0.0] * len(ncycs_1) 171 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 172 173 sfrq_2 = 600.0*1E6 174 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 175 time_T2_2 = 0.06 176 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 177 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 178 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 179 r2eff_errs_2 = [0.0] * len(ncycs_2) 180 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 181 182 sfrq_3 = 700.0*1E6 183 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 184 time_T2_3 = 0.07 185 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 186 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 187 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 188 r2eff_errs_3 = [0.0] * len(ncycs_3) 189 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 190 191 # Collect all exps 192 exps = [exp_1, exp_2, exp_3] 193 194 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 195 dw_arr = [1.0, 2.0, 3.0, 4.0] 196 pA_arr = [0.9] 197 kex_arr = [1000.] 198 199 spins = [ 200 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 201 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 202 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 203 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 204 ] 205 206 # Create the data pipe. 207 pipe_name = 'base pipe' 208 pipe_type = 'relax_disp' 209 pipe_bundle = 'relax_disp' 210 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 211 212 # Generate the sequence. 213 for res_name, res_num, spin_name, params in spins: 214 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 215 216 # Set isotope 217 self.interpreter.spin.isotope('15N', spin_id='@N') 218 219 # Now loop over the experiments, to set the variables in relax. 220 exp_ids = [] 221 for exp_i in exps: 222 sfrq, time_T2, ncycs, r2eff_errs = exp_i 223 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 224 exp_ids.append(exp_id) 225 226 ids = [] 227 for ncyc in ncycs: 228 nu_cpmg = ncyc / time_T2 229 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 230 ids.append(cur_id) 231 232 # Set the spectrometer frequency. 233 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 234 235 # Set the experiment type. 236 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 237 238 # Set the relaxation dispersion CPMG constant time delay T (in s). 239 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 240 241 # Set the relaxation dispersion CPMG frequencies. 242 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 243 244 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 245 246 ### Now do fitting. 247 # Change pipe. 248 249 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 250 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 251 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 252 253 # Now read data in. 254 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 255 exp_id = exp_ids[mi] 256 exp_i = exps[mi] 257 sfrq, time_T2, ncycs, r2eff_errs = exp_i 258 259 # Then loop over the spins. 260 for res_name, res_num, spin_name, params in spins: 261 cur_spin_id = ":%i@%s"%(res_num, spin_name) 262 263 # Define file name 264 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 265 266 # Read in the R2eff file to put into spin structure. 267 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 268 269 # Then select model. 270 self.interpreter.relax_disp.select_model(model=model_analyse) 271 272 # Then cluster 273 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 274 275 # Grid search 276 low_arr = R20 + dw_arr + pA_arr + kex_arr 277 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 278 279 # Then loop over the defined spins and read the parameters. 280 for i in range(len(spins)): 281 res_name, res_num, spin_name, params = spins[i] 282 cur_spin_id = ":%i@%s"%(res_num, spin_name) 283 cur_spin = return_spin(cur_spin_id) 284 285 for mo_param in cur_spin.params: 286 print(mo_param) 287 # The R2 is a dictionary, depending on spectrometer frequency. 288 if isinstance(getattr(cur_spin, mo_param), dict): 289 for key, val in list(getattr(cur_spin, mo_param).items()): 290 should_be = params[mo_param][key] 291 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 292 self.assertAlmostEqual(val, should_be) 293 else: 294 should_be = float(params[mo_param]) 295 val = getattr(cur_spin, mo_param) 296 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 297 self.assertAlmostEqual(val, should_be) 298 299 # Test chi2. 300 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 301 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
302 303
304 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
305 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 306 307 # The path to the data files. 308 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 309 310 # Set pipe name, bundle and type. 311 ds.pipe_name = 'base pipe' 312 ds.pipe_bundle = 'relax_disp' 313 ds.pipe_type = 'relax_disp' 314 315 # Create the data pipe. 316 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 317 318 # Read the spins. 319 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 320 321 # Name the isotope for field strength scaling. 322 self.interpreter.spin.isotope(isotope='15N') 323 324 # Set number of experiments to be used. 325 NR_exp = 70 326 327 # Load the experiments settings file. 328 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 329 expfileslines = expfile.readlines()[:NR_exp] 330 expfile.close() 331 332 # In MHz 333 yOBS = 81.050 334 # In ppm 335 yCAR = 118.078 336 centerPPM_N15 = yCAR 337 338 ## Read the chemical shift data. 339 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 340 341 # The lock power to field, has been found in an calibration experiment. 342 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 343 344 # Apply spectra settings. 345 # Count settings 346 j = 0 347 for i in range(len(expfileslines)): 348 line = expfileslines[i] 349 if line[0] == "#": 350 continue 351 else: 352 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 353 DIRN = line.split()[0] 354 I = int(line.split()[1]) 355 deltadof2 = line.split()[2] 356 dpwr2slock = line.split()[3] 357 ncyc = int(line.split()[4]) 358 trim = float(line.split()[5]) 359 ss = int(line.split()[6]) 360 set_sfrq = float(line.split()[7]) 361 apod_rmsd = float(line.split()[8]) 362 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 363 364 # Calculate spin_lock time 365 time_sl = 2*ncyc*trim 366 367 # Define file name for peak list. 368 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 369 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 370 371 # Load the peak intensities. 372 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 373 374 # Set the peak intensity errors, as defined as the baseplane RMSD. 375 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 376 377 # Set the relaxation dispersion experiment type. 378 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 379 380 # Set The spin-lock field strength, nu1, in Hz 381 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 382 383 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 384 frq_N15_Hz = yOBS * 1E6 385 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 386 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 387 388 # Set The spin-lock offset, omega_rf, in ppm. 389 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 390 391 # Set the relaxation times (in s). 392 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 393 394 # Set the spectrometer frequency. 395 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 396 397 # Add to counter 398 j += 1 399 400 401 print("Testing the number of settings") 402 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 403 self.assertEqual(70, len(expfileslines)) 404 self.assertEqual(69, j) 405 self.assertEqual(69, len(cdp.exp_type)) 406 407 # Cluster spins 408 for curspin in cluster_ids: 409 print("Adding spin %s to cluster"%curspin) 410 self.interpreter.relax_disp.cluster('model_cluster', curspin) 411 412 # De-select for analysis those spins who have not been clustered 413 for free_spin in cdp.clustering['free spins']: 414 print("Deselecting free spin %s"%free_spin) 415 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 416 417 418 #Paper reference values 419 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 420 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 421 ds.ref = dict() 422 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 423 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 424 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 425 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 426 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 427 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 428 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 429 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 430 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 431 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 432 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 433 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 434 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 435 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 436 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 437 438 ds.guess = dict() 439 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 440 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 441 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 442 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 443 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 444 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 445 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 446 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 447 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 448 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 449 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 450 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 451 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 452 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 453 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 454 455 # Assign guess values. 456 for spin, spin_id in spin_loop(return_id=True): 457 if spin_id in cluster_ids: 458 print("spin_id %s in cluster ids"%(spin_id)) 459 spin.kex = ds.guess[spin_id][6] 460 spin.phi_ex = ds.guess[spin_id][10] 461 else: 462 print("spin_id %s NOT in cluster ids"%(spin_id)) 463 464 if read_R1: 465 # Read the R1 data 466 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
467 468
469 - def setup_hansen_cpmg_data(self, model=None):
470 """Set up the data for the test_hansen_cpmg_data_*() system tests. 471 472 @keyword model: The name of the model which will be tested. 473 @type model: str 474 """ 475 476 # Create the data pipe and load the base data. 477 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 478 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 479 self.interpreter.results.read(data_path+sep+'base_pipe') 480 self.interpreter.deselect.spin(':4') 481 482 # Set the nuclear isotope data. 483 self.interpreter.spin.isotope('15N') 484 485 # Create the R2eff data pipe and load the results. 486 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 487 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 488 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 489 self.interpreter.deselect.spin(':4') 490 491 # The model data pipe. 492 pipe_name = "%s - relax_disp" % model 493 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 494 self.interpreter.pipe.switch(pipe_name=pipe_name) 495 496 # Set the model. 497 self.interpreter.relax_disp.select_model(model=model) 498 499 # Copy the data. 500 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
501 502
503 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
504 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 505 506 @keyword model: The name of the model which will be tested. 507 @type model: str 508 """ 509 510 # Create the data pipe and load the base data. 511 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 512 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 513 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 514 515 # Create the R2eff data pipe and load the results. 516 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 517 self.interpreter.pipe.switch(pipe_name='R2eff') 518 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 519 520 # The model data pipe. 521 pipe_name = "%s - relax_disp" % model 522 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 523 self.interpreter.pipe.switch(pipe_name=pipe_name) 524 525 # Set the model. 526 self.interpreter.relax_disp.select_model(model=model) 527 528 # Copy the data. 529 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
530 531
532 - def setup_korzhnev_2005_data(self, data_list=[]):
533 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 534 535 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 536 537 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 538 539 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 540 541 542 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 543 @type data_list: list of str 544 """ 545 546 # Create the data pipe and load the base data. 547 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 548 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 549 550 # Create the spin system. 551 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 553 self.interpreter.spin.element('H', spin_id='@H') 554 self.interpreter.spin.element('N', spin_id='@N') 555 self.interpreter.spin.isotope('1H', spin_id='@H') 556 self.interpreter.spin.isotope('15N', spin_id='@N') 557 558 # Define the magnetic dipole-dipole relaxation interaction. 559 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 560 561 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 562 data = [ 563 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 564 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 566 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 567 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 569 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 570 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 572 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 575 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 576 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 578 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 581 ] 582 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 583 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 584 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 585 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 587 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 588 589 # Loop over the files, reading in the data. 590 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 591 # Skip undesired data. 592 if data_type not in data_list: 593 continue 594 595 # Alias the CPMG frequencies. 596 if data_type == 'SQ': 597 cpmg_frqs = cpmg_frqs_sq 598 elif data_type == '1H SQ': 599 cpmg_frqs = cpmg_frqs_1h_sq 600 elif data_type == 'DQ': 601 cpmg_frqs = cpmg_frqs_dq 602 elif data_type == 'ZQ': 603 cpmg_frqs = cpmg_frqs_zq 604 elif data_type == '1H MQ': 605 cpmg_frqs = cpmg_frqs_1h_mq 606 elif data_type == 'MQ': 607 cpmg_frqs = cpmg_frqs_mq 608 609 # Loop over each CPMG frequency. 610 for cpmg_frq in cpmg_frqs: 611 # The id. 612 new_id = "%s_%s" % (id, cpmg_frq) 613 614 # Set the NMR field strength. 615 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 616 617 # Set the relaxation dispersion experiment type. 618 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 619 620 # Relaxation dispersion CPMG constant time delay T (in s). 621 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 622 623 # Set the CPMG frequency. 624 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 625 626 # Read the R2eff data. 627 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 628 629 # Change the model. 630 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
631 632
633 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
634 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 635 636 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 637 'SOD1-WT' CPMG data to the CR72 dispersion model. 638 639 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 640 Data is for experiment at 25 degree Celcius. 641 """ 642 643 # Create the data pipe and load the base data. 644 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 645 646 # Set experiment settings. sfrq, time_T2, ncyc 647 Exps = [ 648 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 649 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 650 651 # Create base pipe 652 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 653 654 # Loop throug experiments 655 id_lists = [] 656 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 657 # Read spins 658 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 661 # Make spectrum id list 662 id_list = list(key+str(i) for i in range(len(ncycs))) 663 id_lists.append(id_list) 664 665 # Read intensities 666 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 667 668 # Loop over experiments 669 for i in range(len(ncycs)): 670 ncyc = ncycs[i] 671 vcpmg = ncyc/time_T2 672 673 # Test if spectrum is a reference 674 if float(vcpmg) == 0.0: 675 vcpmg = None 676 else: 677 vcpmg = round(float(vcpmg), 3) 678 679 # Set current id 680 current_id = id_list[i] 681 682 # Set the current experiment type. 683 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 684 685 # Set the NMR field strength of the spectrum. 686 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 687 688 # Relaxation dispersion CPMG constant time delay T (in s). 689 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 690 691 # Set the relaxation dispersion CPMG frequencies. 692 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 693 694 # Define replicated 695 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 697 698 # Perform error analysis 699 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 700 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 701 702 # Define isotope 703 self.interpreter.spin.isotope(isotope='15N') 704 705 ############# 706 707 # Define the 64 residues which was used for Global fitting 708 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 709 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 710 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 711 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 712 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 713 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 714 715 # Test number of global 716 self.assertEqual(64, len(glob_assn )) 717 718 ## Turn assignments into relax spin ids. 719 # Define regular expression search 720 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 721 722 # Create list to hold regular expression search 723 relax_glob_ids = [] 724 725 # Loop over assignments 726 for assn in glob_assn: 727 # Make match for the regular search 728 m = r.match(assn) 729 # Convert to relax spin string 730 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 731 732 # Save the relax spin string and the regular search 733 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 734 735 ############# Deselect all spins, and select few spins 736 737 ## Deselect all spins, and select a few for analysis 738 self.interpreter.deselect.all() 739 740 # Select few spins 741 for i in select_spin_index: 742 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 743 744 ############## 745 746 # Prepare for R2eff calculation 747 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 748 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 749 750 # Select model for points calculation 751 MODEL = "R2eff" 752 self.interpreter.relax_disp.select_model(model=MODEL) 753 # Calculate R2eff values 754 self.interpreter.minimise.calculate(verbosity=1)
755 756
757 - def setup_missing_r1_spins(self):
758 """Function for setting up a few spins for the given pipe.""" 759 760 # Path to file. 761 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 762 763 # File with spins. 764 file = open(data_path+sep+'R1_fitted_values.txt') 765 lines = file.readlines() 766 file.close() 767 768 for i, line in enumerate(lines): 769 # Make the string test 770 line_split = line.split() 771 772 if line_split[0] == "#": 773 continue 774 775 mol_name = line_split[0] 776 mol_name = None 777 res_num = int(line_split[1]) 778 res_name = line_split[2] 779 spin_num = line_split[3] 780 spin_num = None 781 spin_name = line_split[4] 782 783 # Create the spin. 784 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
785 786
787 - def setup_paul_schanda_nov_2015(self, outdir=None):
788 """This setup the truncated private data which was provided by Paul Schanda.""" 789 790 # Data path. 791 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Paul_Schanda_2015_Nov' 792 file = data_path + sep + '1_prepare_data.py' 793 794 # Store the out 795 status.outdir = outdir 796 797 # Run script. 798 self.interpreter.script(file=file, dir=None)
799 800
801 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
802 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 803 804 # Reset. 805 self.interpreter.reset() 806 807 # Create the data pipe and load the base data. 808 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 809 self.interpreter.state.load(data_path+sep+'r2eff_values') 810 811 # The model data pipe. 812 model = 'NS R1rho 2-site' 813 pipe_name = "%s - relax_disp" % model 814 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 815 self.interpreter.pipe.switch(pipe_name=pipe_name) 816 817 # Set the model. 818 self.interpreter.relax_disp.select_model(model=model) 819 820 # Copy the data. 821 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 822 823 # Alias the spins. 824 spin1 = cdp.mol[0].res[0].spin[0] 825 spin2 = cdp.mol[0].res[1].spin[0] 826 827 # The R20 keys. 828 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 829 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 830 831 # Set the initial parameter values. 832 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 833 spin1.pA = 0.779782428085762 834 spin1.dw = 7.57855284496424 835 spin1.kex = 1116.7911285203 836 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 837 spin2.pA = 0.826666229688602 838 spin2.dw = 9.5732624231366 839 spin2.kex = 1380.46162655657 840 841 # Test the values when clustering. 842 if clustering: 843 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 844 845 # Low precision optimisation. 846 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 847 848 # Printout. 849 print("\n\nOptimised parameters:\n") 850 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 851 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 852 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 853 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 854 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 855 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 856 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
857 858
859 - def test_baldwin_synthetic(self):
860 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 861 862 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 863 864 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 865 """ 866 867 # The path to the data files. 868 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 869 870 # Create pipe 871 pipe_name = 'base pipe' 872 pipe_type = 'relax_disp' 873 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 874 875 # Create base pipe 876 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 877 878 # Generate the sequence. 879 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 880 881 # Define the isotope. 882 self.interpreter.spin.isotope('1H', spin_id='@H') 883 884 # Build the experiment IDs. 885 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 886 ncycs = [2, 4, 8, 10, 20, 40, 500] 887 ids = [] 888 for ncyc in ncycs: 889 ids.append('CPMG_%s' % ncyc) 890 891 print("\n\nThe experiment IDs are %s." % ids) 892 893 # Set up the metadata for the experiments. 894 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 895 sfrq = 200. * 1E6 896 897 # Total time of CPMG block. 898 Trelax = 0.04 899 900 # First set the 901 for i in range(len(ids)): 902 id = ids[i] 903 # Set the spectrometer frequency. 904 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 905 906 # Set the experiment type. 907 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 908 909 # Set the relaxation dispersion CPMG constant time delay T (in s). 910 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 911 912 # Set the relaxation dispersion CPMG frequencies. 913 ncyc = ncycs[i] 914 nu_cpmg = ncyc / Trelax 915 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 916 917 # Prepare for R2eff reading. 918 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 919 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 920 921 # Try reading the R2eff file. 922 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 923 924 # Check the global data. 925 data = [ 926 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 927 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 928 ['dispersion_points', len(ncycs)], 929 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 930 ['exp_type_list', ['SQ CPMG']], 931 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 932 ['spectrometer_frq_count', 1], 933 ['spectrometer_frq_list', [sfrq]], 934 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 935 ] 936 for name, value in data: 937 # Does it exist? 938 self.assert_(hasattr(cdp, name)) 939 940 # Check the object. 941 obj = getattr(cdp, name) 942 if not isinstance(data, dict): 943 self.assertEqual(obj, value) 944 945 # Check the global dictionary data. 946 else: 947 for id in ids: 948 self.assertEqual(obj[id], value[id]) 949 950 # Check the spin data. 951 n_data = [ 952 [ 50.000000, 10.367900, 0.1], 953 [ 100.000000, 10.146849, 0.1], 954 [ 200.000000, 9.765987, 0.1], 955 [ 250.000000, 9.409789, 0.1], 956 [ 500.000000, 5.829819, 0.1], 957 [ 1000.000000, 3.191928, 0.1], 958 [ 12500.000000, 2.008231, 0.1] 959 ] 960 for disp_point, value, error in n_data: 961 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 962 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 963 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 964 965 # Generate r20 key. 966 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 967 968 ## Now prepare for MODEL calculation. 969 MODEL = "B14" 970 971 # Change pipe. 972 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 973 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 974 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 975 976 # Then select model. 977 self.interpreter.relax_disp.select_model(model=MODEL) 978 979 # Store grid and minimisations results. 980 grid_results = [] 981 mini_results = [] 982 983 # The grid search size (the number of increments per dimension). 984 # If None, use the default values. 985 #GRID = None 986 GRID = 13 987 # Perform Grid Search. 988 if GRID: 989 # Set the R20 parameters in the default grid search using the minimum R2eff value. 990 # This speeds it up considerably. 991 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 992 993 # Then do grid search. 994 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 995 996 # If no Grid search, set the default values. 997 else: 998 for param in MODEL_PARAMS[MODEL]: 999 self.interpreter.value.set(param=param, index=None) 1000 # Do a grid search, which will store the chi2 value. 1001 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1002 1003 # Store result. 1004 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1005 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1006 1007 ## Now do minimisation. 1008 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1009 set_func_tol = 1e-10 1010 set_max_iter = 1000 1011 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1012 1013 # Store result. 1014 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1015 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1016 1017 # Print results. 1018 for i in range(len(grid_results)): 1019 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1020 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1021 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1022 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1023 1024 # Reference values from Baldwin.py. 1025 # Exchange rate = k+ + k- (s-1) 1026 kex = 1000. 1027 # Fractional population of excited state k+/kex 1028 pb = 0.01 1029 # deltaOmega in ppm 1030 dw_ppm = 2. 1031 #relaxation rate of ground (s-1) 1032 R2g = 2. 1033 #relaxation rate of excited (s-1) 1034 R2e = 2. 1035 1036 # Test the parameters which created the data. 1037 # This is for the 1H spin. 1038 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1039 1040 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1041 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1042 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1043 1044
1046 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1047 1048 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1049 """ 1050 1051 # The path to the data files. 1052 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1053 1054 # Create pipe 1055 pipe_name = 'base pipe' 1056 pipe_type = 'relax_disp' 1057 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1058 1059 # Create base pipe 1060 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1061 1062 # Generate the sequence. 1063 # Generate both a 1H spin, and 15N spin. 1064 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1065 1066 # Define the isotope. 1067 self.interpreter.spin.isotope('1H', spin_id='@H') 1068 1069 # Build the experiment IDs. 1070 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1071 ncycs = [2, 4, 8, 10, 20, 40, 500] 1072 ids = [] 1073 for ncyc in ncycs: 1074 ids.append('CPMG_%s' % ncyc) 1075 1076 print("\n\nThe experiment IDs are %s." % ids) 1077 1078 # Set up the metadata for the experiments. 1079 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1080 sfrq = 200. * 1E6 1081 1082 # Total time of CPMG block. 1083 Trelax = 0.04 1084 1085 # First set the 1086 for i in range(len(ids)): 1087 id = ids[i] 1088 # Set the spectrometer frequency. 1089 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1090 1091 # Set the experiment type. 1092 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1093 1094 # Set the relaxation dispersion CPMG constant time delay T (in s). 1095 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1096 1097 # Set the relaxation dispersion CPMG frequencies. 1098 ncyc = ncycs[i] 1099 nu_cpmg = ncyc / Trelax 1100 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1101 1102 # Prepare for R2eff reading. 1103 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1104 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1105 1106 # Try reading the R2eff file. 1107 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1108 1109 # Check the global data. 1110 data = [ 1111 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1112 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1113 ['dispersion_points', len(ncycs)], 1114 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1115 ['exp_type_list', ['SQ CPMG']], 1116 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1117 ['spectrometer_frq_count', 1], 1118 ['spectrometer_frq_list', [sfrq]], 1119 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1120 ] 1121 for name, value in data: 1122 # Does it exist? 1123 self.assert_(hasattr(cdp, name)) 1124 1125 # Check the object. 1126 obj = getattr(cdp, name) 1127 if not isinstance(data, dict): 1128 self.assertEqual(obj, value) 1129 1130 # Check the global dictionary data. 1131 else: 1132 for id in ids: 1133 self.assertEqual(obj[id], value[id]) 1134 1135 # Check the spin data. 1136 n_data = [ 1137 [ 50.000000, 10.286255, 0.1], 1138 [ 100.000000, 10.073083, 0.1], 1139 [ 200.000000, 9.692746, 0.1], 1140 [ 250.000000, 9.382441, 0.1], 1141 [ 500.000000, 6.312396, 0.1], 1142 [ 1000.000000, 3.957029, 0.1], 1143 [ 12500.000000, 2.880420, 0.1] 1144 ] 1145 for disp_point, value, error in n_data: 1146 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1147 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1148 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1149 1150 # Generate r20 key. 1151 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1152 1153 ## Now prepare for MODEL calculation. 1154 MODEL = "B14 full" 1155 1156 # Change pipe. 1157 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1158 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1159 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1160 1161 # Then select model. 1162 self.interpreter.relax_disp.select_model(model=MODEL) 1163 1164 # Store grid and minimisations results. 1165 grid_results = [] 1166 mini_results = [] 1167 clust_results = [] 1168 1169 # The grid search size (the number of increments per dimension). 1170 # If None, use the default values. 1171 #GRID = None 1172 GRID = 13 1173 # Perform Grid Search. 1174 if GRID: 1175 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1176 # This speeds it up considerably. 1177 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1178 1179 # Then do grid search. 1180 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1181 1182 # If no Grid search, set the default values. 1183 else: 1184 for param in MODEL_PARAMS[MODEL]: 1185 self.interpreter.value.set(param=param, index=None) 1186 # Do a grid search, which will store the chi2 value. 1187 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1188 1189 # Store result. 1190 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1191 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1192 1193 ## Now do minimisation. 1194 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1195 set_func_tol = 1e-11 1196 set_max_iter = 10000 1197 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1198 1199 # Store result. 1200 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1201 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1202 1203 print("\n# Now print before and after minimisation-\n") 1204 1205 # Print results. 1206 for i in range(len(grid_results)): 1207 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1208 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1209 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1210 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1211 1212 # Reference values from Baldwin.py. 1213 # Exchange rate = k+ + k- (s-1) 1214 kex = 1000. 1215 # Fractional population of excited state k+/kex 1216 pb = 0.01 1217 # deltaOmega in ppm 1218 dw_ppm = 2. 1219 #relaxation rate of ground (s-1) 1220 R2g = 2. 1221 #relaxation rate of excited (s-1) 1222 R2e = 100. 1223 1224 # Test the parameters which created the data. 1225 # This is for the 1H spin. 1226 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1227 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1228 1229 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1230 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1231 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1232 1233
1234 - def x_test_bmrb_sub_cpmg(self):
1235 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1236 This uses CPMG data from: 1237 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1238 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1239 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1240 """ 1241 1242 # Define path to data 1243 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1244 1245 # Read data. 1246 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1247 1248 # Set element 1249 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1250 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1251 # Rename molecule from None to 'HEWL' 1252 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1253 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1254 1255 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1256 print(spin_id) 1257 if resn == 'C': 1258 print(resi, resn) 1259 1260 # Select the thiol state of the system. 1261 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1262 self.interpreter.bmrb.thiol_state(state='not reported') 1263 1264 # relax_data.temp_calibration(ri_id=None, method=None) 1265 1266 # Call display of bmrb. 1267 self.interpreter.bmrb.display()
1268 1269
1271 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1272 1273 # Clear the data store. 1274 self.interpreter.reset() 1275 1276 # Load the state. 1277 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1278 self.interpreter.state.load(state, force=True) 1279 1280 # Model selection - to catch the failure. 1281 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1282 1283
1285 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1286 1287 # Clear the data store. 1288 self.interpreter.reset() 1289 1290 # Load the state. 1291 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1292 self.interpreter.state.load(state, force=True) 1293 1294 # Execute the auto-analysis (fast). 1295 relax_disp.Relax_disp.opt_func_tol = 1e-5 1296 relax_disp.Relax_disp.opt_max_iterations = 1000 1297 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1298 1299
1301 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1302 1303 # Clear the data store. 1304 self.interpreter.reset() 1305 1306 # Load the state. 1307 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1308 self.interpreter.state.load(state, force=True) 1309 1310 # Execute the auto-analysis (fast). 1311 relax_disp.Relax_disp.opt_func_tol = 1e-5 1312 relax_disp.Relax_disp.opt_max_iterations = 1000 1313 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1314 1315
1317 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1318 1319 # Clear the data store. 1320 self.interpreter.reset() 1321 1322 # Load the state. 1323 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1324 self.interpreter.state.load(state, force=True) 1325 1326 # Run the calculation. 1327 self.interpreter.minimise.calculate(verbosity=1)
1328 1329
1331 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1332 1333 # Clear the data store. 1334 self.interpreter.reset() 1335 1336 # Load the state. 1337 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1338 self.interpreter.state.load(state, force=True) 1339 1340 # Execute the auto-analysis (fast). 1341 relax_disp.Relax_disp.opt_func_tol = 1e-5 1342 relax_disp.Relax_disp.opt_max_iterations = 1000 1343 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1344 1345
1347 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1348 1349 # Clear the data store. 1350 self.interpreter.reset() 1351 1352 # Load the state. 1353 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1354 self.interpreter.state.load(state, force=True) 1355 1356 # Execute the auto-analysis (fast). 1357 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1358 relax_disp.Relax_disp.opt_func_tol = 1e-5 1359 relax_disp.Relax_disp.opt_max_iterations = 1000 1360 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=3, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1361 1362
1364 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1365 1366 # Base data setup. 1367 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1368 1369
1371 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1372 1373 # Base data setup. 1374 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1375 1376
1378 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1379 1380 # Base data setup. 1381 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1382 1383
1385 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1386 1387 # Base data setup. 1388 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1389 1390
1392 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1393 1394 # Clear the data store. 1395 self.interpreter.reset() 1396 1397 # Load the state. 1398 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1399 self.interpreter.state.load(state, force=True) 1400 1401 param = 'k_AB' 1402 1403 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1404 print(spin_id, spin.params) 1405 if param in spin.params: 1406 print(spin_id, spin.k_AB, spin.k_AB_err) 1407 1408 # Perform write. 1409 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1410 1411 1412 # Test the header of the value.write parameter r2. 1413 param = 'r2' 1414 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1415 1416 file = open(self.tmpdir+sep+'%s.out'%param) 1417 lines = file.readlines() 1418 file.close() 1419 1420 for i, line in enumerate(lines): 1421 # Make the string test 1422 line_split = line.split() 1423 print(line_split) 1424 1425 if len(line_split) > 1: 1426 # Break at parameter header. 1427 if line_split[0] == "#" and line_split[1] == 'mol_name': 1428 nr_split_header = len(line_split) 1429 nr_split_header_i = i 1430 break 1431 1432 # Call the line after. 1433 line_split_val = lines[nr_split_header_i + 1].split() 1434 print(line_split_val) 1435 1436 # Assert that the number of columns is equal, plus 1 for "#". 1437 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1438 1439 # Test the header of the value.write for parameter r2eff. 1440 param = 'r2eff' 1441 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1442 1443 file = open(self.tmpdir+sep+'%s.out'%param) 1444 lines = file.readlines() 1445 file.close() 1446 1447 for i, line in enumerate(lines): 1448 # Make the string test 1449 line_split = line.split() 1450 print(line_split) 1451 1452 if len(line_split) > 1: 1453 # Break at parameter header. 1454 if line_split[0] == "#" and line_split[1] == 'mol_name': 1455 nr_split_header = len(line_split) 1456 nr_split_header_i = i 1457 break 1458 1459 # Call the line after. 1460 line_split_val = lines[nr_split_header_i + 1].split() 1461 print(line_split_val) 1462 1463 # Assert that the number of columns is equal, plus 1 for "#". 1464 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1465 1466
1468 """Catch U{bug #23186<https://gna.org/bugs/?23186>}: Error calculation of individual parameter "dw" from Monte-Carlo, is based on first spin.""" 1469 1470 # Clear the data store. 1471 self.interpreter.reset() 1472 1473 # Load the state. 1474 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1475 self.interpreter.state.load(state, force=True) 1476 1477 # Dic key to spectrometer frq. 1478 dickey = 'SQ CPMG - 599.89086220 MHz' 1479 1480 # First get the resi 0 array of sim r2a. 1481 resi_0_r2a = [] 1482 1483 # Assign spins 1484 res0 = cdp.mol[0].res[0].spin[0] 1485 res1 = cdp.mol[0].res[1].spin[0] 1486 1487 print("Chi2 before call to minimise: %3.3f"%res0.chi2) 1488 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0) 1489 print("Chi2 after call to minimise: %3.3f"%res0.chi2) 1490 1491 # Loop over the dics in spin. 1492 for cdic in res0.r2a_sim: 1493 resi_0_r2a.append(cdic[dickey]) 1494 1495 # Get stats with numpy 1496 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1497 1498 # First get the resi 86 array of sim r2a. 1499 resi_86_r2a = [] 1500 1501 # Loop over the dics in spin. 1502 for cdic in res1.r2a_sim: 1503 resi_86_r2a.append(cdic[dickey]) 1504 1505 # Get stats with numpy 1506 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1507 1508 # Then get for dw. 1509 1510 # First get the array of sim dw. 1511 resi_0_dw = res0.dw_sim 1512 resi_86_dw = res1.dw_sim 1513 1514 # Get stats with numpy 1515 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1516 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1517 1518 # Then get for spin independent parameter. 1519 1520 # First get the array of sim dw. 1521 resi_0_kAB = res0.k_AB_sim 1522 resi_86_kAB = res1.k_AB_sim 1523 1524 # Get stats with numpy 1525 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1526 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1527 1528 # Assume they both std of k_AB values are equal 1529 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1530 1531 # Perform error analysis. 1532 self.interpreter.monte_carlo.error_analysis() 1533 1534 # Check values for k_AB. 1535 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err) 1536 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err) 1537 1538 # Check values for r2a. 1539 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey]) 1540 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey]) 1541 1542 # Check values for dw. 1543 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err) 1544 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err) 1545 1546 # The following is for Bug #23619: (https://gna.org/bugs/index.php?23619): Stored chi2 sim values from Monte-Carlo simulations does not equal normal chi2 values. 1547 # This is to show that this bug is invalid. The "very" different chi2 values stems from r2eff points being back-calculated values rather than original measured values. 1548 1549 # Check calculates the same Monte-Carlo chi2 values 1550 self.interpreter.monte_carlo.setup(number=3) 1551 self.interpreter.monte_carlo.create_data(method='back_calc') 1552 self.interpreter.monte_carlo.initial_values() 1553 1554 # Assign original data instead of back_calculated error. 1555 res0.r2eff_sim[0] = copy.copy(res0.r2eff) 1556 res0.r2eff_sim[1] = copy.copy(res0.r2eff) 1557 res0.r2eff_sim[2] = copy.copy(res0.r2eff) 1558 res1.r2eff_sim[0] = copy.copy(res1.r2eff) 1559 res1.r2eff_sim[1] = copy.copy(res1.r2eff) 1560 res1.r2eff_sim[2] = copy.copy(res1.r2eff) 1561 1562 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000) 1563 self.interpreter.monte_carlo.error_analysis() 1564 1565 # Get the simulation array and calculate the average 1566 spin_chi2_mc = res0.chi2 1567 spin_chi2_mc_sim = res0.chi2_sim 1568 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim) 1569 1570 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc) 1571 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim) 1572 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave) 1573 1574 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1575 1576
1578 """Catch U{bug #24601<https://gna.org/bugs/?24601>}, the failure of optimisation of the 'R2eff' model with missing data.""" 1579 1580 # Execute the script. 1581 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_missing_data.py')
1582 1583
1585 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1586 1587 # Define path to data 1588 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1589 1590 # Read data. 1591 self.interpreter.results.read(prev_data_path + sep + 'results') 1592 1593 # Now count number 1594 graph_nr = 1 1595 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1596 print("\nGraph nr %i" % graph_nr) 1597 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1598 print(exp_type, frq, offset, point, time) 1599 graph_nr += 1 1600 1601 ## Possibly do an error analysis. 1602 1603 # Check if intensity errors have already been calculated by the user. 1604 precalc = True 1605 for spin in spin_loop(skip_desel=True): 1606 # No structure. 1607 if not hasattr(spin, 'peak_intensity_err'): 1608 precalc = False 1609 break 1610 1611 # Determine if a spectrum ID is missing from the list. 1612 for id in cdp.spectrum_ids: 1613 if id not in spin.peak_intensity_err: 1614 precalc = False 1615 break 1616 1617 # Skip. 1618 if precalc: 1619 print("Skipping the error analysis as it has already been performed.") 1620 1621 else: 1622 # Loop over the spectrometer frequencies. 1623 for frq in loop_frq(): 1624 # Generate a list of spectrum IDs matching the frequency. 1625 ids = [] 1626 for id in cdp.spectrum_ids: 1627 # Check that the spectrometer frequency matches. 1628 match_frq = True 1629 if frq != None and cdp.spectrometer_frq[id] != frq: 1630 match_frq = False 1631 1632 # Add the ID. 1633 if match_frq: 1634 ids.append(id) 1635 1636 # Run the error analysis on the subset. 1637 self.interpreter.spectrum.error_analysis(subset=ids) 1638 1639 print("has_exponential_exp_type:", has_exponential_exp_type()) 1640 1641 model = 'R2eff' 1642 self.interpreter.relax_disp.select_model(model) 1643 1644 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1645 #delattr(spin, 'r2eff') 1646 #delattr(spin, 'r2eff_err') 1647 #delattr(spin, 'i0') 1648 #delattr(spin, 'i0_err') 1649 setattr(spin, 'r2eff', {}) 1650 setattr(spin, 'r2eff_err', {}) 1651 setattr(spin, 'i0', {}) 1652 setattr(spin, 'i0_err', {}) 1653 1654 # Do Grid Search 1655 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1656 1657 # Start dic. 1658 my_dic = {} 1659 1660 # Define counter for maximum elements in the numpy array list 1661 NE = 0 1662 NS = 1 1663 NM = 0 1664 NO = 0 1665 ND = 0 1666 NT = 0 1667 1668 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1669 # Save to counter. 1670 if ei > NE: 1671 NE = ei 1672 if mi > NM: 1673 NM = mi 1674 if oi > NO: 1675 NO = oi 1676 if di > ND: 1677 ND = di 1678 1679 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1680 # Save to counter. 1681 if ti > NT: 1682 NT = ti 1683 1684 # Add 1 to counter, since index start from 0. 1685 NE = NE + 1 1686 NM = NM + 1 1687 NO = NO + 1 1688 ND = ND + 1 1689 NT = NT + 1 1690 1691 # Make data array. 1692 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1693 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1694 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1695 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1696 param_key_list = [] 1697 1698 1699 # Loop over each spectrometer frequency and dispersion point. 1700 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1701 # Add key to dic. 1702 my_dic[spin_id] = {} 1703 1704 # Generate spin string. 1705 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1706 1707 # Loop over the parameters. 1708 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1709 1710 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1711 # Generate the param_key. 1712 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1713 1714 # Append key. 1715 param_key_list.append(param_key) 1716 1717 # Add key to dic. 1718 my_dic[spin_id][param_key] = {} 1719 1720 # Get the value. 1721 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1722 i0_value = getattr(cur_spin, 'i0')[param_key] 1723 1724 # Save to dic. 1725 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1726 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1727 1728 ## Now try do a line of best fit by least squares. 1729 # The peak intensities, errors and times. 1730 values = [] 1731 errors = [] 1732 times = [] 1733 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1734 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1735 values.append(value) 1736 1737 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1738 errors.append(error) 1739 times.append(time) 1740 1741 # Save to numpy arrays. 1742 values_arr[ei, 0, mi, oi, di, ti] = value 1743 errors_arr[ei, 0, mi, oi, di, ti] = error 1744 times_arr[ei, 0, mi, oi, di, ti] = time 1745 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1746 1747 # y= A exp(x * k) 1748 # w[i] = ln(y[i]) 1749 # int[i] = i0 * exp( - times[i] * r2eff); 1750 w = log(array(values)) 1751 x = - array(times) 1752 n = len(times) 1753 1754 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1755 a = 1./n * sum(w) - b * 1./n * sum(x) 1756 R2eff_est = b 1757 i0_est = exp(a) 1758 1759 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1760 my_dic[spin_id][param_key]['i0_est'] = i0_est 1761 1762 # Print value. 1763 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1764 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1765 1766 1767 # Do minimisation. 1768 set_func_tol = 1e-25 1769 set_max_iter = int(1e7) 1770 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1771 1772 # Loop over each spectrometer frequency and dispersion point. 1773 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1774 # Generate spin string. 1775 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1776 1777 # Loop over the parameters. 1778 print("Optimised parameters for spin: %s" % (spin_string)) 1779 1780 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1781 # Generate the param_key. 1782 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1783 1784 # Get the value. 1785 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1786 i0_value = getattr(cur_spin, 'i0')[param_key] 1787 1788 # Extract from dic. 1789 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1790 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1791 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1792 i0_est = my_dic[spin_id][param_key]['i0_est'] 1793 1794 # Print value. 1795 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1796 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1797 1798 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1799 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1800 1801 print(NE, NS, NM, NO, ND, NT) 1802 for param_key in param_key_list: 1803 print(" '%s'," % param_key) 1804 print(values_arr.shape) 1805 1806 # Save arrays to profiling. 1807 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1808 #save(data_path + "values_arr", values_arr) 1809 #save(data_path + "errors_arr", errors_arr) 1810 #save(data_path + "times_arr", times_arr) 1811 #save(data_path + "struct_arr", struct_arr) 1812 1813
1814 - def test_bug_atul_srivastava(self):
1815 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1816 shows it is exponential fitting, but only one time point is added per file. 1817 1818 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1819 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1820 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1821 1822 """ 1823 1824 # Data path. 1825 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1826 file = data_path + sep + 'bug_script.py' 1827 1828 # Run script. 1829 self.interpreter.script(file=file, dir=None) 1830 1831 # The grid search size (the number of increments per dimension). 1832 GRID_INC = 11 1833 1834 # Check-data. 1835 ################# 1836 1837 # Loop over spins, to see current setup. 1838 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1839 print(mol_name, resi, resn, spin_id) 1840 1841 # Loop over setup. 1842 for id in cdp.exp_type: 1843 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1844 1845 1846 # Manual minimisation. 1847 ################# 1848 if True: 1849 # Set the model. 1850 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1851 1852 # Check if intensity errors have already been calculated. 1853 check_intensity_errors() 1854 1855 # Calculate the R2eff values for the fixed relaxation time period data types. 1856 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1857 self.interpreter.minimise.calculate() 1858 1859 # Optimise the model. 1860 else: 1861 constraints = False 1862 min_algor = 'Newton' 1863 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1864 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1865 1866 # Inspect. 1867 if False: 1868 # Loop over attributes. 1869 par_attr_list = ['r2eff', 'i0'] 1870 1871 # Collect the estimation data. 1872 my_dic = {} 1873 param_key_list = [] 1874 est_keys = [] 1875 est_key = 'grid' 1876 est_keys.append(est_key) 1877 spin_id_list = [] 1878 1879 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1880 # Add key to dic. 1881 my_dic[spin_id] = {} 1882 1883 # Add key for estimate. 1884 my_dic[spin_id][est_key] = {} 1885 1886 # Add spin key to list. 1887 spin_id_list.append(spin_id) 1888 1889 # Generate spin string. 1890 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1891 1892 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1893 # Generate the param_key. 1894 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1895 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1896 1897 # Append key. 1898 param_key_list.append(param_key) 1899 1900 # Add key to dic. 1901 my_dic[spin_id][est_key][param_key] = {} 1902 1903 # Get the value. 1904 # Loop over err attributes. 1905 for par_attr in par_attr_list: 1906 if hasattr(cur_spin, par_attr): 1907 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1908 else: 1909 get_par_attr = 0.0 1910 1911 # Save to dic. 1912 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1913 1914 # Check number of values. 1915 values = [] 1916 errors = [] 1917 times = [] 1918 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1919 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1920 values.append(value) 1921 1922 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1923 errors.append(error) 1924 times.append(time) 1925 1926 # Save to dic. 1927 my_dic[spin_id][est_key][param_key]['values'] = values 1928 my_dic[spin_id][est_key][param_key]['errors'] = errors 1929 my_dic[spin_id][est_key][param_key]['times'] = times 1930 1931 # Analysis variables. 1932 ##################### 1933 1934 # The dispersion models. 1935 MODELS = ['R2eff', 'No Rex'] 1936 1937 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1938 MC_NUM = 10 1939 1940 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1941 MC_SIM_ALL_MODELS = False 1942 1943 # The results directory. 1944 RESULTS_DIR = ds.tmpdir 1945 1946 # The directory of results of an earlier analysis without clustering. 1947 PRE_RUN_DIR = None 1948 1949 # The model selection technique to use. 1950 MODSEL = 'AIC' 1951 1952 # The flag for only using numeric models in the final model selection. 1953 NUMERIC_ONLY = False 1954 1955 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1956 INSIGNIFICANCE = 1.0 1957 1958 # Auto-analysis execution. 1959 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1960 1961
1963 """Test data, where peak intensities are negative in CPMG 1964 1965 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1966 """ 1967 1968 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1969 1970 # Create the spins 1971 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1972 1973 # Name the isotope for field strength scaling. 1974 self.interpreter.spin.isotope(isotope='15N') 1975 1976 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1977 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1978 1979 # Loop over the spectra settings. 1980 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1981 1982 # Make empty ncyclist 1983 ncyclist = [] 1984 1985 i = 0 1986 for line in ncycfile: 1987 ncyc = line.split()[0] 1988 time_T2 = float(line.split()[1]) 1989 vcpmg = line.split()[2] 1990 set_sfrq = float(line.split()[3]) 1991 rmsd_err = float(line.split()[4]) 1992 1993 # Test if spectrum is a reference 1994 if float(vcpmg) == 0.0: 1995 vcpmg = None 1996 else: 1997 vcpmg = round(float(vcpmg), 3) 1998 1999 # Add ncyc to list 2000 ncyclist.append(int(ncyc)) 2001 2002 # Set the current spectrum id 2003 current_id = "Z_A%s"%(i) 2004 2005 # Set the current experiment type. 2006 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 2007 2008 # Set the peak intensity errors, as defined as the baseplane RMSD. 2009 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 2010 2011 # Set the NMR field strength of the spectrum. 2012 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 2013 2014 # Relaxation dispersion CPMG constant time delay T (in s). 2015 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 2016 2017 # Set the relaxation dispersion CPMG frequencies. 2018 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 2019 2020 i += 1 2021 2022 # Specify the duplicated spectra. 2023 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 2024 2025 # Delete replicate spectrum 2026 #self.interpreter.spectrum.delete('Z_A15') 2027 2028 MODELS = [MODEL_R2EFF, MODEL_NOREX] 2029 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 2030 2031 results_dir = ds.tmpdir 2032 2033 # Execute 2034 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 2035 2036 # Check spin less R2eff points. 2037 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 2038 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 2039 if spin_id == ':4@N': 2040 self.assertEqual(len(cur_spin.r2eff), 14) 2041 else: 2042 self.assertEqual(len(cur_spin.r2eff), 15)
2043 2044
2045 - def test_check_missing_r1(self):
2046 """Test of the check_missing_r1() function.""" 2047 2048 # Set up some spins. 2049 self.setup_missing_r1_spins() 2050 2051 # Set variables. 2052 exp_type = 'R1rho' 2053 frq = 800.1 * 1E6 2054 2055 spectrum_id='test' 2056 2057 # Set an experiment type to the pipe. 2058 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2059 2060 # Set a frequency to loop through. 2061 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2062 2063 # Check R1 for DPL94. 2064 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2065 self.assertEqual(check_missing_r1_return, True) 2066 2067 # Check R1 for R2eff. 2068 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2069 self.assertEqual(check_missing_r1_return, False) 2070 2071 # The path to the data files. 2072 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2073 2074 # Now load some R1 data. 2075 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 2076 2077 # Check R1. 2078 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2079 self.assertEqual(check_missing_r1_return, False)
2080 2081
2083 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2084 2085 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2086 2087 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2088 """ 2089 2090 # Reset. 2091 #self.interpreter.reset() 2092 2093 ## Set Experiments. 2094 model_create = 'B14' 2095 #model_create = 'NS CPMG 2-site expanded' 2096 model_analyse = 'NS CPMG 2-site 3D' 2097 2098 # Exp 1 2099 sfrq_1 = 599.8908617*1E6 2100 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2101 time_T2_1 = 0.06 2102 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2103 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2104 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2105 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2106 2107 sfrq_2 = 499.8908617*1E6 2108 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2109 time_T2_2 = 0.05 2110 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2111 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2112 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2113 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2114 2115 # Collect all exps 2116 exps = [exp_1, exp_2] 2117 2118 spins = [ 2119 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2120 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2121 ] 2122 2123 # Collect the data to be used. 2124 ds.data = [model_create, model_analyse, spins, exps] 2125 2126 # The tmp directory. None is the local directory. 2127 ds.tmpdir = ds.tmpdir 2128 2129 # The results directory. None is the local directory. 2130 #ds.resdir = None 2131 ds.resdir = ds.tmpdir 2132 2133 # Do r20_from_min_r2eff ?. 2134 ds.r20_from_min_r2eff = True 2135 2136 # Remove insignificant level. 2137 ds.insignificance = 0.0 2138 2139 # The grid search size (the number of increments per dimension). 2140 ds.GRID_INC = None 2141 2142 # The do clustering. 2143 ds.do_cluster = True 2144 2145 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2146 # The default value is 1e-25. 2147 ds.set_func_tol = 1e-1 2148 2149 # The maximum number of iterations. 2150 # The default value is 1e7. 2151 ds.set_max_iter = 1000 2152 2153 # The verbosity level. 2154 ds.verbosity = 1 2155 2156 # The rel_change WARNING level. 2157 ds.rel_change = 0.05 2158 2159 # The plot_curves. 2160 ds.plot_curves = False 2161 2162 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2163 ds.sherekhan_input = False 2164 2165 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2166 ds.opendx = False 2167 2168 # The set r2eff err. 2169 ds.r2eff_err = 0.1 2170 2171 # The print result info. 2172 ds.print_res = True 2173 2174 # Execute the script. 2175 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2176 2177 cur_spins = ds.data[2] 2178 # Compare results. 2179 for i in range(len(cur_spins)): 2180 res_name, res_num, spin_name, params = cur_spins[i] 2181 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2182 cur_spin = return_spin(cur_spin_id) 2183 2184 grid_params = ds.grid_results[i][3] 2185 2186 # Extract the clust results. 2187 min_params = ds.clust_results[i][3] 2188 # Now read the parameters. 2189 print("For spin: '%s'"%cur_spin_id) 2190 for mo_param in cur_spin.params: 2191 # The R2 is a dictionary, depending on spectrometer frequency. 2192 if isinstance(getattr(cur_spin, mo_param), dict): 2193 grid_r2 = grid_params[mo_param] 2194 min_r2 = min_params[mo_param] 2195 set_r2 = params[mo_param] 2196 for key, val in list(set_r2.items()): 2197 grid_r2_frq = grid_r2[key] 2198 min_r2_frq = min_r2[key] 2199 set_r2_frq = set_r2[key] 2200 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2201 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2202 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2203 if rel_change > ds.rel_change: 2204 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2205 print("###################################") 2206 2207 ## Make test on R2. 2208 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2209 else: 2210 grid_val = grid_params[mo_param] 2211 min_val = min_params[mo_param] 2212 set_val = params[mo_param] 2213 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2214 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2215 if rel_change > ds.rel_change: 2216 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2217 print("###################################") 2218 2219 ## Make test on parameters. 2220 if mo_param == 'dw': 2221 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2222 elif mo_param == 'kex': 2223 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2224 elif mo_param == 'pA': 2225 self.assertAlmostEqual(set_val, min_val, 2)
2226 2227
2229 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2230 2231 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2232 2233 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2234 """ 2235 2236 # Reset. 2237 #self.interpreter.reset() 2238 2239 ## Set Experiments. 2240 model_create = 'B14' 2241 #model_create = 'NS CPMG 2-site expanded' 2242 model_analyse = 'NS CPMG 2-site star' 2243 2244 # Exp 1 2245 sfrq_1 = 599.8908617*1E6 2246 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2247 time_T2_1 = 0.06 2248 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2249 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2250 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2251 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2252 2253 sfrq_2 = 499.8908617*1E6 2254 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2255 time_T2_2 = 0.05 2256 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2257 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2258 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2259 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2260 2261 # Collect all exps 2262 exps = [exp_1, exp_2] 2263 2264 spins = [ 2265 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2266 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2267 ] 2268 2269 # Collect the data to be used. 2270 ds.data = [model_create, model_analyse, spins, exps] 2271 2272 # The tmp directory. None is the local directory. 2273 ds.tmpdir = ds.tmpdir 2274 2275 # The results directory. None is the local directory. 2276 #ds.resdir = None 2277 ds.resdir = ds.tmpdir 2278 2279 # Do r20_from_min_r2eff ?. 2280 ds.r20_from_min_r2eff = True 2281 2282 # Remove insignificant level. 2283 ds.insignificance = 0.0 2284 2285 # The grid search size (the number of increments per dimension). 2286 ds.GRID_INC = None 2287 2288 # The do clustering. 2289 ds.do_cluster = True 2290 2291 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2292 # The default value is 1e-25. 2293 ds.set_func_tol = 1e-1 2294 2295 # The maximum number of iterations. 2296 # The default value is 1e7. 2297 ds.set_max_iter = 1000 2298 2299 # The verbosity level. 2300 ds.verbosity = 1 2301 2302 # The rel_change WARNING level. 2303 ds.rel_change = 0.05 2304 2305 # The plot_curves. 2306 ds.plot_curves = False 2307 2308 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2309 ds.sherekhan_input = False 2310 2311 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2312 ds.opendx = False 2313 2314 # The set r2eff err. 2315 ds.r2eff_err = 0.1 2316 2317 # The print result info. 2318 ds.print_res = True 2319 2320 # Execute the script. 2321 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2322 2323 cur_spins = ds.data[2] 2324 # Compare results. 2325 for i in range(len(cur_spins)): 2326 res_name, res_num, spin_name, params = cur_spins[i] 2327 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2328 cur_spin = return_spin(cur_spin_id) 2329 2330 grid_params = ds.grid_results[i][3] 2331 2332 # Extract the clust results. 2333 min_params = ds.clust_results[i][3] 2334 # Now read the parameters. 2335 print("For spin: '%s'"%cur_spin_id) 2336 for mo_param in cur_spin.params: 2337 # The R2 is a dictionary, depending on spectrometer frequency. 2338 if isinstance(getattr(cur_spin, mo_param), dict): 2339 grid_r2 = grid_params[mo_param] 2340 min_r2 = min_params[mo_param] 2341 set_r2 = params[mo_param] 2342 for key, val in list(set_r2.items()): 2343 grid_r2_frq = grid_r2[key] 2344 min_r2_frq = min_r2[key] 2345 set_r2_frq = set_r2[key] 2346 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2347 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2348 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2349 if rel_change > ds.rel_change: 2350 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2351 print("###################################") 2352 2353 ## Make test on R2. 2354 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2355 else: 2356 grid_val = grid_params[mo_param] 2357 min_val = min_params[mo_param] 2358 set_val = params[mo_param] 2359 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2360 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2361 if rel_change > ds.rel_change: 2362 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2363 print("###################################") 2364 2365 ## Make test on parameters. 2366 if mo_param == 'dw': 2367 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2368 elif mo_param == 'kex': 2369 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2370 elif mo_param == 'pA': 2371 self.assertAlmostEqual(set_val, min_val, 2)
2372 2373
2375 """Test synthetic cpmg data. 2376 2377 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2378 """ 2379 2380 # Reset. 2381 #self.interpreter.reset() 2382 2383 ## Set Experiments. 2384 model_create = 'NS CPMG 2-site 3D' 2385 #model_create = 'NS CPMG 2-site expanded' 2386 model_analyse = 'CR72' 2387 # Exp 1 2388 sfrq_1 = 599.8908617*1E6 2389 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2390 time_T2_1 = 0.06 2391 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2392 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2393 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2394 2395 sfrq_2 = 499.8908617*1E6 2396 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2397 time_T2_2 = 0.05 2398 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2399 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2400 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2401 2402 # Collect all exps 2403 exps = [exp_1, exp_2] 2404 2405 spins = [ 2406 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2407 ] 2408 2409 # Collect the data to be used. 2410 ds.data = [model_create, model_analyse, spins, exps] 2411 2412 # The tmp directory. None is the local directory. 2413 ds.tmpdir = ds.tmpdir 2414 2415 # The results directory. None is the local directory. 2416 #ds.resdir = None 2417 ds.resdir = ds.tmpdir 2418 2419 # Do r20_from_min_r2eff ?. 2420 ds.r20_from_min_r2eff = True 2421 2422 # Remove insignificant level. 2423 ds.insignificance = 0.0 2424 2425 # The grid search size (the number of increments per dimension). 2426 ds.GRID_INC = 8 2427 2428 # The do clustering. 2429 ds.do_cluster = False 2430 2431 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2432 # The default value is 1e-25. 2433 ds.set_func_tol = 1e-9 2434 2435 # The maximum number of iterations. 2436 # The default value is 1e7. 2437 ds.set_max_iter = 1000 2438 2439 # The verbosity level. 2440 ds.verbosity = 1 2441 2442 # The rel_change WARNING level. 2443 ds.rel_change = 0.05 2444 2445 # The plot_curves. 2446 ds.plot_curves = False 2447 2448 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2449 ds.sherekhan_input = False 2450 2451 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2452 ds.opendx = False 2453 2454 # The set r2eff err. 2455 ds.r2eff_err = 0.1 2456 2457 # The print result info. 2458 ds.print_res = False 2459 2460 # Execute the script. 2461 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2462 2463 cur_spins = ds.data[2] 2464 # Compare results. 2465 for i in range(len(cur_spins)): 2466 res_name, res_num, spin_name, params = cur_spins[i] 2467 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2468 cur_spin = return_spin(cur_spin_id) 2469 2470 grid_params = ds.grid_results[i][3] 2471 min_params = ds.min_results[i][3] 2472 # Now read the parameters. 2473 print("For spin: '%s'"%cur_spin_id) 2474 for mo_param in cur_spin.params: 2475 # The R2 is a dictionary, depending on spectrometer frequency. 2476 if isinstance(getattr(cur_spin, mo_param), dict): 2477 grid_r2 = grid_params[mo_param] 2478 min_r2 = min_params[mo_param] 2479 set_r2 = params[mo_param] 2480 for key, val in list(set_r2.items()): 2481 grid_r2_frq = grid_r2[key] 2482 min_r2_frq = min_r2[key] 2483 set_r2_frq = set_r2[key] 2484 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2485 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2486 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2487 if rel_change > ds.rel_change: 2488 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2489 print("###################################") 2490 2491 ## Make test on R2. 2492 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2493 else: 2494 grid_val = grid_params[mo_param] 2495 min_val = min_params[mo_param] 2496 set_val = params[mo_param] 2497 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2498 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2499 if rel_change > ds.rel_change: 2500 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2501 print("###################################") 2502 2503 ## Make test on parameters. 2504 if mo_param == 'dw': 2505 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2506 elif mo_param == 'kex': 2507 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2508 elif mo_param == 'pA': 2509 self.assertAlmostEqual(set_val, min_val, 3)
2510 2511
2513 """Test synthetic cpmg data. 2514 2515 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2516 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2517 """ 2518 2519 # Reset. 2520 #self.interpreter.reset() 2521 2522 ## Set Experiments. 2523 model_create = 'NS CPMG 2-site 3D' 2524 #model_create = 'NS CPMG 2-site expanded' 2525 model_analyse = 'B14' 2526 # Exp 1 2527 sfrq_1 = 599.8908617*1E6 2528 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2529 time_T2_1 = 0.06 2530 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2531 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2532 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2533 2534 sfrq_2 = 499.8908617*1E6 2535 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2536 time_T2_2 = 0.05 2537 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2538 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2539 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2540 2541 # Collect all exps 2542 exps = [exp_1, exp_2] 2543 2544 spins = [ 2545 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2546 ] 2547 2548 # Collect the data to be used. 2549 ds.data = [model_create, model_analyse, spins, exps] 2550 2551 # The tmp directory. None is the local directory. 2552 ds.tmpdir = ds.tmpdir 2553 2554 # The results directory. None is the local directory. 2555 #ds.resdir = None 2556 ds.resdir = ds.tmpdir 2557 2558 # Do r20_from_min_r2eff ?. 2559 ds.r20_from_min_r2eff = True 2560 2561 # Remove insignificant level. 2562 ds.insignificance = 0.0 2563 2564 # The grid search size (the number of increments per dimension). 2565 ds.GRID_INC = 8 2566 2567 # The do clustering. 2568 ds.do_cluster = False 2569 2570 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2571 # The default value is 1e-25. 2572 ds.set_func_tol = 1e-9 2573 2574 # The maximum number of iterations. 2575 # The default value is 1e7. 2576 ds.set_max_iter = 1000 2577 2578 # The verbosity level. 2579 ds.verbosity = 1 2580 2581 # The rel_change WARNING level. 2582 ds.rel_change = 0.05 2583 2584 # The plot_curves. 2585 ds.plot_curves = False 2586 2587 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2588 ds.sherekhan_input = False 2589 2590 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2591 ds.opendx = False 2592 2593 # The set r2eff err. 2594 ds.r2eff_err = 0.1 2595 2596 # The print result info. 2597 ds.print_res = False 2598 2599 # Execute the script. 2600 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2601 2602 cur_spins = ds.data[2] 2603 # Compare results. 2604 for i in range(len(cur_spins)): 2605 res_name, res_num, spin_name, params = cur_spins[i] 2606 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2607 cur_spin = return_spin(cur_spin_id) 2608 2609 grid_params = ds.grid_results[i][3] 2610 min_params = ds.min_results[i][3] 2611 # Now read the parameters. 2612 print("For spin: '%s'"%cur_spin_id) 2613 for mo_param in cur_spin.params: 2614 # The R2 is a dictionary, depending on spectrometer frequency. 2615 if isinstance(getattr(cur_spin, mo_param), dict): 2616 grid_r2 = grid_params[mo_param] 2617 min_r2 = min_params[mo_param] 2618 set_r2 = params[mo_param] 2619 for key, val in list(set_r2.items()): 2620 grid_r2_frq = grid_r2[key] 2621 min_r2_frq = min_r2[key] 2622 set_r2_frq = set_r2[key] 2623 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2624 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2625 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2626 if rel_change > ds.rel_change: 2627 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2628 print("###################################") 2629 2630 ## Make test on R2. 2631 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2632 else: 2633 grid_val = grid_params[mo_param] 2634 min_val = min_params[mo_param] 2635 set_val = params[mo_param] 2636 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2637 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2638 if rel_change > ds.rel_change: 2639 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2640 print("###################################") 2641 2642 ## Make test on parameters. 2643 if mo_param == 'dw': 2644 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2645 elif mo_param == 'kex': 2646 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2647 elif mo_param == 'pA': 2648 self.assertAlmostEqual(set_val, min_val, 6)
2649 2650
2652 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2653 2654 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2655 """ 2656 2657 # Reset. 2658 #self.interpreter.reset() 2659 2660 ## Set Experiments. 2661 model_create = 'NS CPMG 2-site 3D' 2662 #model_create = 'NS CPMG 2-site expanded' 2663 model_analyse = 'CR72' 2664 2665 # Exp 1 2666 sfrq_1 = 599.8908617*1E6 2667 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2668 time_T2_1 = 0.06 2669 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2670 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2671 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2672 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2673 2674 sfrq_2 = 499.8908617*1E6 2675 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2676 time_T2_2 = 0.05 2677 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2678 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2679 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2680 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2681 2682 # Collect all exps 2683 exps = [exp_1, exp_2] 2684 2685 spins = [ 2686 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2687 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2688 ] 2689 2690 # Collect the data to be used. 2691 ds.data = [model_create, model_analyse, spins, exps] 2692 2693 # The tmp directory. None is the local directory. 2694 ds.tmpdir = ds.tmpdir 2695 2696 # The results directory. None is the local directory. 2697 #ds.resdir = None 2698 ds.resdir = ds.tmpdir 2699 2700 # Do r20_from_min_r2eff ?. 2701 ds.r20_from_min_r2eff = True 2702 2703 # Remove insignificant level. 2704 ds.insignificance = 0.0 2705 2706 # The grid search size (the number of increments per dimension). 2707 ds.GRID_INC = 13 2708 2709 # The do clustering. 2710 ds.do_cluster = True 2711 2712 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2713 # The default value is 1e-25. 2714 ds.set_func_tol = 1e-8 2715 2716 # The maximum number of iterations. 2717 # The default value is 1e7. 2718 ds.set_max_iter = 10000 2719 2720 # The verbosity level. 2721 ds.verbosity = 1 2722 2723 # The rel_change WARNING level. 2724 ds.rel_change = 0.05 2725 2726 # The plot_curves. 2727 ds.plot_curves = False 2728 2729 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2730 ds.sherekhan_input = False 2731 2732 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2733 ds.opendx = False 2734 2735 # The set r2eff err. 2736 ds.r2eff_err = 0.1 2737 2738 # The print result info. 2739 ds.print_res = False 2740 2741 # Execute the script. 2742 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2743 2744 cur_spins = ds.data[2] 2745 # Compare results. 2746 for i in range(len(cur_spins)): 2747 res_name, res_num, spin_name, params = cur_spins[i] 2748 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2749 cur_spin = return_spin(cur_spin_id) 2750 2751 grid_params = ds.grid_results[i][3] 2752 2753 # Extract the clust results. 2754 min_params = ds.clust_results[i][3] 2755 # Now read the parameters. 2756 print("For spin: '%s'"%cur_spin_id) 2757 for mo_param in cur_spin.params: 2758 # The R2 is a dictionary, depending on spectrometer frequency. 2759 if isinstance(getattr(cur_spin, mo_param), dict): 2760 grid_r2 = grid_params[mo_param] 2761 min_r2 = min_params[mo_param] 2762 set_r2 = params[mo_param] 2763 for key, val in list(set_r2.items()): 2764 grid_r2_frq = grid_r2[key] 2765 min_r2_frq = min_r2[key] 2766 set_r2_frq = set_r2[key] 2767 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2768 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2769 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2770 if rel_change > ds.rel_change: 2771 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2772 print("###################################") 2773 2774 ## Make test on R2. 2775 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2776 else: 2777 grid_val = grid_params[mo_param] 2778 min_val = min_params[mo_param] 2779 set_val = params[mo_param] 2780 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2781 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2782 if rel_change > ds.rel_change: 2783 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2784 print("###################################") 2785 2786 ## Make test on parameters. 2787 if mo_param == 'dw': 2788 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2789 elif mo_param == 'kex': 2790 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2791 elif mo_param == 'pA': 2792 self.assertAlmostEqual(set_val, min_val, 2)
2793 2794
2796 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2797 2798 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2799 """ 2800 2801 # Reset. 2802 #self.interpreter.reset() 2803 2804 ## Set Experiments. 2805 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2806 model_analyse = 'CR72' 2807 # Exp 1 2808 sfrq_1 = 599.8908617*1E6 2809 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2810 time_T2_1 = 0.06 2811 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2812 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2813 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2814 2815 sfrq_2 = 499.8908617*1E6 2816 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2817 time_T2_2 = 0.05 2818 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2819 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2820 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2821 2822 # Collect all exps 2823 exps = [exp_1, exp_2] 2824 2825 spins = [ 2826 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2827 ] 2828 2829 # Collect the data to be used. 2830 ds.data = [model_create, model_analyse, spins, exps] 2831 2832 # The tmp directory. None is the local directory. 2833 ds.tmpdir = ds.tmpdir 2834 2835 # The results directory. None is the local directory. 2836 #ds.resdir = None 2837 ds.resdir = ds.tmpdir 2838 2839 # Do r20_from_min_r2eff ?. 2840 ds.r20_from_min_r2eff = True 2841 2842 # Remove insignificant level. 2843 ds.insignificance = 0.0 2844 2845 # The grid search size (the number of increments per dimension). 2846 ds.GRID_INC = None 2847 2848 # The do clustering. 2849 ds.do_cluster = False 2850 2851 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2852 # The default value is 1e-25. 2853 ds.set_func_tol = 1e-9 2854 2855 # The maximum number of iterations. 2856 # The default value is 1e7. 2857 ds.set_max_iter = 1000 2858 2859 # The verbosity level. 2860 ds.verbosity = 1 2861 2862 # The rel_change WARNING level. 2863 ds.rel_change = 0.05 2864 2865 # The plot_curves. 2866 ds.plot_curves = False 2867 2868 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2869 ds.sherekhan_input = False 2870 2871 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2872 ds.opendx = False 2873 2874 # The set r2eff err. 2875 ds.r2eff_err = 0.1 2876 2877 # The print result info. 2878 ds.print_res = False 2879 2880 # Execute the script. 2881 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2882 2883 # Get the spins. 2884 cur_spins = ds.data[2] 2885 2886 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2887 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2888 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2889 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2890 2891 # Copy R2eff, but not the original parameters 2892 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2893 2894 # Then select model. 2895 self.interpreter.relax_disp.select_model(model=model_analyse) 2896 2897 # Define dx.map settings. 2898 ds.dx_inc = 4 2899 ds.dx_params = ['dw', 'pA', 'kex'] 2900 2901 res_name, res_num, spin_name, params = cur_spins[0] 2902 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2903 cur_spin = return_spin(cur_spin_id) 2904 2905 print("Params for dx map is") 2906 print(ds.dx_params) 2907 print("Point param for dx map is") 2908 print(ds.dx_set_val) 2909 cur_model = model_analyse.replace(' ', '_') 2910 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2911 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2912 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2913 2914 ## Check for file creation 2915 # Set filepaths. 2916 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2917 map_net = ds.tmpdir+sep+file_name_map+".net" 2918 map_general = ds.tmpdir+sep+file_name_map+".general" 2919 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2920 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2921 2922 point_general = ds.tmpdir+sep+file_name_point+".general" 2923 point_point = ds.tmpdir+sep+file_name_point 2924 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2925 2926 # Test the files exists. 2927 self.assert_(access(map_cfg, F_OK)) 2928 self.assert_(access(map_net, F_OK)) 2929 self.assert_(access(map_general, F_OK)) 2930 self.assert_(access(map_par, F_OK)) 2931 self.assert_(access(map_plot, F_OK)) 2932 self.assert_(access(point_general, F_OK)) 2933 self.assert_(access(point_point, F_OK)) 2934 self.assert_(access(point_par, F_OK)) 2935 2936 # Open the files for testing. 2937 # Check the cfg file. 2938 print("\nChecking the dx map .cfg file.") 2939 res_file = [ 2940 '//'+"\n", 2941 '//'+"\n", 2942 '// time: Thu May 8 18:55:31 2014'+"\n", 2943 '//'+"\n", 2944 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2945 '//'+"\n", 2946 '//'+"\n", 2947 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2948 '// title: value = Control Panel'+"\n", 2949 '//'+"\n", 2950 '// workspace: width = 251, height = 142'+"\n", 2951 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2952 '//'+"\n", 2953 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2954 '// selections: maximum = 2, current = 0 '+"\n", 2955 '// option[0]: name = "Colour", value = 1'+"\n", 2956 '// option[1]: name = "Grey", value = 2'+"\n", 2957 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2958 '// label: value = Colour Selector'+"\n", 2959 '//'+"\n", 2960 '// node Image[3]:'+"\n", 2961 '// title: value = Surface'+"\n", 2962 '// depth: value = 24'+"\n", 2963 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2964 ] 2965 file = open(map_cfg, 'r') 2966 lines = file.readlines() 2967 file.close() 2968 for i in range(len(res_file)): 2969 # Skip time point 2970 if i == 2: 2971 continue 2972 self.assertEqual(res_file[i], lines[i]) 2973 2974 print("\nChecking the dx map .general file.") 2975 res_file = [ 2976 'file = CR72_map_1_N'+"\n", 2977 'grid = 5 x 5 x 5'+"\n", 2978 'format = ascii'+"\n", 2979 'interleaving = field'+"\n", 2980 'majority = row'+"\n", 2981 'field = data'+"\n", 2982 'structure = scalar'+"\n", 2983 'type = float'+"\n", 2984 'dependency = positions'+"\n", 2985 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2986 ''+"\n", 2987 'end'+"\n", 2988 ] 2989 file = open(map_general, 'r') 2990 lines = file.readlines() 2991 file.close() 2992 for i in range(len(res_file)): 2993 # Skip time point 2994 #if i == 2: 2995 # continue 2996 self.assertEqual(res_file[i], lines[i]) 2997 2998 print("\nChecking the dx point .general file.") 2999 res_file = [ 3000 'file = CR72_point_1_N'+"\n", 3001 'points = 2'+"\n", 3002 'format = ascii'+"\n", 3003 'interleaving = field'+"\n", 3004 'field = locations, field0'+"\n", 3005 'structure = 3-vector, scalar'+"\n", 3006 'type = float, float'+"\n", 3007 ''+"\n", 3008 'end'+"\n", 3009 ] 3010 file = open(point_general, 'r') 3011 lines = file.readlines() 3012 file.close() 3013 for i in range(len(res_file)): 3014 # Skip time point 3015 #if i == 2: 3016 # continue 3017 self.assertEqual(res_file[i], lines[i]) 3018 3019 print("\nChecking the dx point point file.") 3020 res_file = [ 3021 '0.8 3.92 0.39964 1'+"\n", 3022 '0.76981 3.9169 0.41353 1'+"\n", 3023 ] 3024 file = open(point_point, 'r') 3025 lines = file.readlines() 3026 file.close() 3027 for i in range(len(res_file)): 3028 # Skip time point 3029 #if i == 2: 3030 # continue 3031 self.assertEqual(res_file[i], lines[i]) 3032 3033 print("\nChecking the dx point par file.") 3034 res_file = [ 3035 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3036 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3037 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 3038 ] 3039 res_file2 = [ 3040 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3041 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3042 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 3043 ] # Python 2.5 and 3.1. 3044 file = open(point_par, 'r') 3045 lines = file.readlines() 3046 file.close() 3047 for i in range(len(res_file)): 3048 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 3049 self.assertEqual(res_file[i], lines[i]) 3050 3051 print("\nChecking the matplotlib surface plot file.") 3052 res_file = [ 3053 'from copy import deepcopy'+"\n", 3054 'import numpy as np'+"\n", 3055 'import scipy.interpolate'+"\n", 3056 'from numpy.ma import masked_where'+"\n", 3057 ''+"\n", 3058 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3059 'import matplotlib.pyplot as plt'+"\n", 3060 'from matplotlib import cm'+"\n", 3061 ''+"\n", 3062 '# Open file and get header.'+"\n", 3063 'mapfile_name = "%s.par"'%file_name_map+"\n", 3064 'pointfile_name = "%s.par"'%file_name_point+"\n", 3065 ''+"\n", 3066 ] 3067 file = open(map_plot, 'r') 3068 lines = file.readlines() 3069 file.close() 3070 for i in range(len(res_file)): 3071 self.assertEqual(res_file[i], lines[i])
3072 3073
3075 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3076 3077 # Reset. 3078 self.interpreter.reset() 3079 3080 # Load the base data. 3081 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3082 self.interpreter.state.load(data_path+sep+'r2eff_values') 3083 3084 # The type. 3085 curve_type = get_curve_type(id='500_133.33.in') 3086 self.assertEqual(curve_type, 'fixed time')
3087 3088
3089 - def test_curve_type_r1rho_exponential(self, model=None):
3090 """Test the curve type detection using the 'M61' exponential test data.""" 3091 3092 # Reset. 3093 self.interpreter.reset() 3094 3095 # Load the base data. 3096 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3097 self.interpreter.state.load(data_path+sep+'r2eff_values') 3098 3099 # The type. 3100 curve_type = get_curve_type(id='nu_2000_ncyc9') 3101 self.assertEqual(curve_type, 'exponential')
3102 3103
3104 - def test_curve_type_r1rho_fixed_time(self, model=None):
3105 """Test the curve type detection using the 'TP02' fixed time test data.""" 3106 3107 # Reset. 3108 self.interpreter.reset() 3109 3110 # Load the base data. 3111 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3112 self.interpreter.state.load(data_path+sep+'r2eff_values') 3113 3114 # The type. 3115 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3116 self.assertEqual(curve_type, 'fixed time')
3117 3118
3119 - def test_dpl94_data_to_dpl94(self):
3120 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3121 3122 # Fixed time variable. 3123 ds.fixed = True 3124 3125 # Execute the script. 3126 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3127 3128 # The original parameters. 3129 i0 = [100000.0, 20000.0] 3130 r1rho_prime = [2.25, 24.0] 3131 pA = 0.7 3132 kex = 1000.0 3133 delta_omega = [1.0, 2.0] 3134 phi_ex = [] 3135 for i in range(2): 3136 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3137 3138 # Switch to the 'DPL94' model data pipe, then check for each spin. 3139 self.interpreter.pipe.switch('DPL94 - relax_disp') 3140 spin_index = 0 3141 for spin, spin_id in spin_loop(return_id=True): 3142 # Printout. 3143 print("\nSpin %s." % spin_id) 3144 3145 # Check the fitted parameters. 3146 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3147 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3148 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3149 3150 # Increment the spin index. 3151 spin_index += 1
3152 3153
3154 - def test_dx_map_clustered(self):
3155 """Test making dx_map for residues under clustered calculation. 3156 3157 This uses CPMG data from: 3158 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3159 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3160 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3161 """ 3162 3163 # Define path to data 3164 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3165 3166 # Read data. 3167 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3168 3169 # Get residue of interest. 3170 cur_spin_id = ":%i@%s"%(52, 'N') 3171 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3172 3173 # Get the spin container. 3174 cur_spin = return_spin(cur_spin_id) 3175 3176 # Get the chi2 value 3177 pre_chi2 = cur_spin.chi2 3178 3179 # Then do a local minimisation. 3180 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3181 self.interpreter.minimise.calculate() 3182 3183 # Get the chi2 value after calculation. 3184 calc_chi2 = cur_spin.chi2 3185 3186 # Assert calculation is equal. 3187 self.assertAlmostEqual(pre_chi2, calc_chi2) 3188 3189 # Define dx.map settings. 3190 dx_inc = 2 3191 dx_inc_sides = dx_inc / 2 3192 3193 dx_params = ['dw', 'pA', 'kex'] 3194 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3195 3196 print("Params for dx map is") 3197 print(dx_params) 3198 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3199 print(dx_point_clustered_min) 3200 3201 # Define file_names. 3202 cur_model = 'CR72' 3203 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3204 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3205 3206 # Step-size of parameter is 10 % 3207 param_delta = 0.1 3208 3209 # Determine bounds for lower and upper 3210 lower = [] 3211 upper = [] 3212 for i, param_val in enumerate(dx_point_clustered_min): 3213 param = dx_params[i] 3214 step_val = param_delta * param_val 3215 step_length = step_val * dx_inc_sides 3216 3217 # Calculate value 3218 low_val = param_val - step_length 3219 lower.append(low_val) 3220 3221 upp_val = param_val + step_length 3222 upper.append(upp_val) 3223 3224 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3225 3226 # If the number of increments are 2, there will be 3 point calculations per parameter. 3227 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3228 dx_param_indexes = dx_inc + 1 3229 dx_point_index = dx_inc_sides + 1 3230 3231 # Find the line number. 3232 line = 1 3233 for i in range(1, dx_param_indexes + 1): 3234 for j in range(1, dx_param_indexes + 1): 3235 for k in range(1, dx_param_indexes + 1): 3236 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3237 line_chi2 = line 3238 # Add to line counter. 3239 line += 1 3240 3241 # Define temporary folder. 3242 result_dir = self.tmpdir 3243 3244 # For testing. 3245 #result_dir = None 3246 #lower = None 3247 #upper = None 3248 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3249 3250 3251 # Then do the map. 3252 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3253 3254 # Print where to locate values. 3255 nr_chi2_val = dx_param_indexes**3 3256 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3257 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3258 3259 ## Check for file creation 3260 # Set filepaths. 3261 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3262 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3263 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3264 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3265 3266 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3267 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3268 3269 # Test the files exists. 3270 self.assert_(access(map_cfg, F_OK)) 3271 self.assert_(access(map_net, F_OK)) 3272 self.assert_(access(map_general, F_OK)) 3273 self.assert_(access(point_general, F_OK)) 3274 self.assert_(access(point_point, F_OK)) 3275 3276 # Open the file, and assert the chi2 value is as expected. 3277 get_data = extract_data(file=map_name) 3278 3279 # Extract line 0, column 0. 3280 test = float(get_data[line_chi2-1][0]) 3281 3282 # Assert. 3283 self.assertAlmostEqual(test, pre_chi2, 6)
3284 3285
3287 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3288 3289 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3290 3291 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3292 """ 3293 3294 # Define path to data 3295 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3296 3297 # Read data. 3298 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3299 3300 # Get residue of interest. 3301 cur_spin_id = ":%i@%s"%(65, 'N') 3302 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3303 3304 # Get the spin container. 3305 cur_spin = return_spin(cur_spin_id) 3306 3307 # Get the chi2 value 3308 pre_chi2 = cur_spin.chi2 3309 3310 # Then do a local minimisation. 3311 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3312 self.interpreter.minimise.calculate() 3313 3314 # Get the chi2 value after calculation. 3315 calc_chi2 = cur_spin.chi2 3316 3317 # Assert calculation is equal. 3318 self.assertAlmostEqual(pre_chi2, calc_chi2) 3319 3320 # Define dx.map settings. 3321 dx_inc = 2 3322 dx_params = ['dw', 'k_AB', 'r2a'] 3323 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3324 3325 print("Params for dx map is") 3326 print(dx_params) 3327 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3328 print(dx_point_clustered_min) 3329 3330 # Define file_names. 3331 cur_model = 'TSMFK01' 3332 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3333 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3334 3335 # Determine bounds for lower and upper 3336 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3337 upper = [19.0, 2.4, 9.5] 3338 3339 # Define temporary folder. 3340 result_dir = self.tmpdir 3341 3342 # For testing. 3343 #result_dir = None 3344 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3345 3346 # Then do the map. 3347 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3348 3349 # Print where to locate values. 3350 nr_chi2_val = (dx_inc + 1)**3 3351 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3352 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3353 3354 ## Check for file creation 3355 # Set filepaths. 3356 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3357 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3358 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3359 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3360 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3361 3362 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3363 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3364 3365 # Test the files exists. 3366 self.assert_(access(map_cfg, F_OK)) 3367 self.assert_(access(map_net, F_OK)) 3368 self.assert_(access(map_general, F_OK)) 3369 self.assert_(access(map_par, F_OK)) 3370 self.assert_(access(point_general, F_OK)) 3371 self.assert_(access(point_point, F_OK)) 3372 3373 print("\nParams for dx map is") 3374 print(dx_params) 3375 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3376 print(dx_point_clustered_min, "\n") 3377 3378 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3379 get_data = extract_data(file=map_par) 3380 3381 # Extract line 1, column 9. 3382 test = float(get_data[1][9]) 3383 3384 # Print data if map contain a lower value than the global minimised value. 3385 if test < pre_chi2: 3386 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3387 for line in get_data: 3388 print(line)
3389 3390 # Assert that the initial global chi2 is lower than the map value. 3391 3392 # The following test was taken out, since this a particular interesting case. 3393 # There exist a double minimum, where relax has not found the global minimum. 3394 # This is due to not grid searching for R2A, but using the minimum 3395 #self.assert_(pre_chi2 < test) 3396 3397
3398 - def test_estimate_r2eff_err(self):
3399 """Test the user function for estimating R2eff errors from exponential curve fitting. 3400 3401 This follows Task 7822. 3402 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3403 3404 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3405 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3406 """ 3407 3408 # Cluster residues 3409 cluster_ids = [ 3410 ":13@N", 3411 ":15@N", 3412 ":16@N", 3413 ":25@N", 3414 ":26@N", 3415 ":28@N", 3416 ":39@N", 3417 ":40@N", 3418 ":41@N", 3419 ":43@N", 3420 ":44@N", 3421 ":45@N", 3422 ":49@N", 3423 ":52@N", 3424 ":53@N"] 3425 3426 # Load the data. 3427 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3428 3429 # The dispersion models. 3430 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3431 3432 # The grid search size (the number of increments per dimension). 3433 GRID_INC = None 3434 3435 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3436 MC_NUM = 3 3437 3438 # Model selection technique. 3439 MODSEL = 'AIC' 3440 3441 # Execute the auto-analysis (fast). 3442 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3443 OPT_FUNC_TOL = 1e-25 3444 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3445 OPT_MAX_ITERATIONS = 10000000 3446 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3447 3448 result_dir_name = ds.tmpdir 3449 3450 # Make all spins free 3451 for curspin in cluster_ids: 3452 self.interpreter.relax_disp.cluster('free spins', curspin) 3453 # Shut them down 3454 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3455 3456 # Select only a subset of spins for global fitting 3457 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3458 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3459 3460 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3461 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3462 3463 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3464 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3465 3466 # Set the model. 3467 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3468 3469 # Check if intensity errors have already been calculated. 3470 check_intensity_errors() 3471 3472 # Do a grid search. 3473 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3474 3475 # Minimise. 3476 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3477 3478 # Estimate R2eff errors. 3479 self.interpreter.relax_disp.r2eff_err_estimate() 3480 3481 r1_fit = True 3482 3483 # Run the analysis. 3484 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3485 3486 # Verify the data. 3487 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3488 3489
3491 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3492 3493 This follows Task 7822. 3494 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3495 3496 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3497 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3498 """ 3499 3500 # Cluster residues 3501 cluster_ids = [ 3502 ":13@N", 3503 ":15@N", 3504 ":16@N", 3505 ":25@N", 3506 ":26@N", 3507 ":28@N", 3508 ":39@N", 3509 ":40@N", 3510 ":41@N", 3511 ":43@N", 3512 ":44@N", 3513 ":45@N", 3514 ":49@N", 3515 ":52@N", 3516 ":53@N"] 3517 3518 # Load the data. 3519 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3520 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3521 3522 # Set pipe name, bundle and type. 3523 pipe_name = 'base pipe' 3524 pipe_bundle = 'relax_disp' 3525 pipe_type = 'relax_disp' 3526 3527 # Create the data pipe. 3528 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3529 3530 file = data_path + '1_setup_r1rho_GUI.py' 3531 self.interpreter.script(file=file, dir=None) 3532 3533 # The dispersion models. 3534 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3535 3536 # The grid search size (the number of increments per dimension). 3537 GRID_INC = None 3538 3539 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3540 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3541 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3542 EXP_MC_NUM = -1 3543 3544 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3545 MC_NUM = 3 3546 3547 # Model selection technique. 3548 MODSEL = 'AIC' 3549 3550 # Execute the auto-analysis (fast). 3551 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3552 OPT_FUNC_TOL = 1e-25 3553 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3554 OPT_MAX_ITERATIONS = 10000000 3555 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3556 3557 # Make all spins free 3558 #for curspin in cluster_ids: 3559 # self.interpreter.relax_disp.cluster('free spins', curspin) 3560 # # Shut them down 3561 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3562 3563 # Make all spins free 3564 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3565 3566 # Select only a subset of spins for global fitting 3567 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3568 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3569 3570 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3571 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3572 3573 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3574 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3575 3576 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3577 print(spin_id) 3578 3579 result_dir_name = self.tmpdir 3580 r1_fit = True 3581 3582 # Run the analysis. 3583 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3584 3585 # Verify the data. 3586 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3587 3588
3590 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3591 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3592 3593 This follows Task 7822. 3594 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3595 3596 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3597 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3598 3599 NOTE: The difference in the methods was due to a bug in relax! 3600 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3601 3602 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3603 """ 3604 3605 # Define data path. 3606 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3607 3608 # Create pipe. 3609 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3610 3611 # Read results for 2000 MC simulations. 3612 self.interpreter.results.read(prev_data_path + sep + 'results') 3613 3614 # Start dic. 3615 my_dic = {} 3616 param_key_list = [] 3617 3618 # Do boot strapping ? 3619 do_boot = True 3620 if do_boot: 3621 min_algor = 'Newton' 3622 min_options = () 3623 sim_boot = 200 3624 scaling_list = [1.0, 1.0] 3625 3626 # First check sim values. 3627 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3628 # Add key to dic. 3629 my_dic[spin_id] = {} 3630 3631 # Loop over sim. 3632 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3633 # Loop over all exp type. 3634 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3635 # Generate the param_key. 3636 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3637 r2eff_sim_point = r2eff_sim[param_key] 3638 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3639 3640 # Assert point are higher than 0.0. 3641 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3642 #print(point_info) 3643 self.assert_(r2eff_sim_point > 0.0) 3644 self.assert_(i0_sim_point > 0.0) 3645 3646 # Get the data. 3647 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3648 # Generate spin string. 3649 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3650 3651 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3652 # Generate the param_key. 3653 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3654 3655 # Loop over all sim, and collect data. 3656 r2eff_sim_l = [] 3657 i0_sim_l = [] 3658 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3659 i0_sim = cur_spin.i0_sim[i] 3660 3661 r2eff_sim_i = r2eff_sim[param_key] 3662 r2eff_sim_l.append(r2eff_sim_i) 3663 i0_sim_i = i0_sim[param_key] 3664 i0_sim_l.append(i0_sim_i) 3665 3666 # Take the standard deviation of all values. 3667 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3668 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3669 3670 # Append key. 3671 param_key_list.append(param_key) 3672 3673 # Add key to dic. 3674 my_dic[spin_id][param_key] = {} 3675 3676 # Get the value. 3677 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3678 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3679 i0 = getattr(cur_spin, 'i0')[param_key] 3680 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3681 3682 # Save to dic. 3683 my_dic[spin_id][param_key]['r2eff'] = r2eff 3684 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3685 my_dic[spin_id][param_key]['i0'] = i0 3686 my_dic[spin_id][param_key]['i0_err'] = i0_err 3687 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3688 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3689 3690 # Assert values are equal 3691 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3692 self.assertAlmostEqual(i0_sim_err, i0_err) 3693 3694 if do_boot: 3695 values = [] 3696 errors = [] 3697 times = [] 3698 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3699 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3700 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3701 times.append(time) 3702 3703 # Convert to numpy array. 3704 values = asarray(values) 3705 errors = asarray(errors) 3706 times = asarray(times) 3707 3708 R_m_sim_l = [] 3709 I0_m_sim_l = [] 3710 for j in range(sim_boot): 3711 if j in range(0, 100000, 100): 3712 print("Simulation %i"%j) 3713 # Start minimisation. 3714 3715 # Produce errors 3716 I_err = [] 3717 for j, error in enumerate(errors): 3718 I_error = gauss(values[j], error) 3719 I_err.append(I_error) 3720 # Convert to numpy array. 3721 I_err = asarray(I_err) 3722 3723 x0 = [r2eff, i0] 3724 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3725 3726 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3727 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3728 R_m_sim_l.append(R_m_sim_j) 3729 I0_m_sim_l.append(I0_m_sim_j) 3730 3731 # Get stats on distribution. 3732 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3733 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3734 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3735 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3736 3737 3738 # A new data pipe. 3739 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3740 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3741 3742 # Delete old errors. 3743 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3744 delattr(cur_spin, 'r2eff_err') 3745 delattr(cur_spin, 'i0_err') 3746 3747 # Set the model. 3748 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3749 3750 # Estimate R2eff and errors. 3751 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3752 3753 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3754 # Generate spin string. 3755 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3756 3757 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3758 # Generate the param_key. 3759 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3760 3761 # Get the value. 3762 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3763 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3764 i0_est = getattr(cur_spin, 'i0')[param_key] 3765 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3766 3767 # Get from dic. 3768 r2eff = my_dic[spin_id][param_key]['r2eff'] 3769 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3770 i0 = my_dic[spin_id][param_key]['i0'] 3771 i0_err = my_dic[spin_id][param_key]['i0_err'] 3772 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3773 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3774 3775 if do_boot: 3776 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3777 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3778 else: 3779 r2eff_boot_err = 0.0 3780 i0_boot_err = 0.0 3781 3782 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3783 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3784 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3785 3786 3787 # Now do it manually. 3788 estimate_r2eff(method='scipy.optimize.leastsq') 3789 3790 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3791 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3792 3793 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3794 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3795 3796 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3797 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3798 3799 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3800 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3801 3802 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3803 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3804 3805 3806
3807 - def test_exp_fit(self):
3808 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3809 3810 # Execute the script. 3811 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3812 3813 # The original exponential curve parameters. 3814 res_data = [ 3815 [15., 10., 20000., 25000.], 3816 [12., 11., 50000., 51000.], 3817 [17., 9., 100000., 96000.] 3818 ] 3819 3820 # List of parameters which do not belong to the model. 3821 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3822 3823 # Checks for each residue. 3824 for i in range(len(res_data)): 3825 # Printout. 3826 print("\nResidue number %s." % (i+1)) 3827 3828 # Check the fitted parameters. 3829 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3830 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3831 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3832 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3833 3834 # Check the simulation errors. 3835 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3836 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3837 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3838 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3839 3840 # Check that certain parameters are not present. 3841 for param in blacklist: 3842 print("\tChecking for the absence of the '%s' parameter." % param) 3843 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3844 3845 # Check the clustering information. 3846 self.assert_(hasattr(cdp, 'clustering')) 3847 keys = ['free spins', 'cluster'] 3848 for key in keys: 3849 self.assert_(key in cdp.clustering) 3850 self.assert_('test' not in cdp.clustering) 3851 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3852 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3853 3854
3855 - def test_finite_value(self):
3856 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3857 3858 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3859 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3860 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3861 3862 scaling_list = [1.0, 1.0] 3863 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3864 3865 R = - 500. 3866 I0 = 1000. 3867 params = [R, I0] 3868 3869 chi2 = model.func(params) 3870 3871 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3872 self.assertNotEqual(chi2, inf)
3873 3874
3875 - def test_hansen_catia_input(self):
3876 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3877 3878 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3879 """ 3880 3881 # Load the R2eff results file. 3882 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3883 self.interpreter.results.read(file_name) 3884 self.interpreter.deselect.spin(':4') 3885 3886 # The spin isotopes. 3887 self.interpreter.spin.isotope("15N") 3888 3889 # Generate the input files. 3890 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3891 3892 # Check the r2eff set files. 3893 print("\nChecking the R2eff input set files.") 3894 files = ['data_set_500.inp', 'data_set_500.inp'] 3895 for file in files: 3896 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3897 data_set_500 = [ 3898 "ID=500\n", 3899 "Sfrq = 500\n", 3900 "Temperature = 0.0\n", 3901 "Nucleus = N15\n", 3902 "Couplednucleus = H1\n", 3903 "Time_equil = 0.0\n", 3904 "Pwx_cp = 0.0\n", 3905 "Taub = 0.0\n", 3906 "Time_T2 = 0.03\n", 3907 "Xcar = 0.0\n", 3908 "Seqfil = CW_CPMG\n", 3909 "Minerror = (2.%;0.5/s)\n", 3910 "Basis = (Iph_7)\n", 3911 "Format = (0;1;2)\n", 3912 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3913 "Data = (\n", 3914 " [70N;spin_70_N_500.cpmg];\n", 3915 " [71N;spin_71_N_500.cpmg];\n", 3916 ")\n", 3917 ] 3918 file = open(ds.tmpdir+sep+files[0]) 3919 lines = file.readlines() 3920 file.close() 3921 for i in range(len(data_set_500)): 3922 # Skip the data directory, as this is a random file name. 3923 if i == 14: 3924 continue 3925 3926 self.assertEqual(data_set_500[i], lines[i]) 3927 3928 # Check the r2eff files. 3929 print("\nChecking the R2eff input files.") 3930 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3931 for file in files: 3932 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3933 spin_70_N_500 = [ 3934 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3935 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3936 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3937 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3938 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3939 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3940 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3941 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3942 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3943 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3944 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3945 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3946 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3947 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3948 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3949 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3950 ] 3951 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3952 lines = file.readlines() 3953 file.close() 3954 for i in range(len(lines)): 3955 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3956 for i in range(len(spin_70_N_500)): 3957 self.assertEqual(spin_70_N_500[i], lines[i]) 3958 3959 # Check the main file. 3960 print("\nChecking the main CATIA execution file.") 3961 main_file = [ 3962 "ReadDataset(data_set_500.inp)\n", 3963 "ReadDataset(data_set_800.inp)\n", 3964 "ReadParam_Global(ParamGlobal.inp)\n", 3965 "ReadParam_Local(ParamSet1.inp)\n", 3966 "\n", 3967 "FreeLocalParam(all;Omega;false)\n", 3968 "FreeLocalParam(all;R1iph_500;false)\n", 3969 "FreeLocalParam(all;R1iph_800;false)\n", 3970 "\n", 3971 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3972 "\n", 3973 "PrintParam(output/GlobalParam.fit;global)\n", 3974 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3975 "PrintData(output/)\n", 3976 "\n", 3977 "ChiSq(all;all)\n", 3978 "exit(0)\n" 3979 ] 3980 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3981 lines = file.readlines() 3982 file.close() 3983 for i in range(len(main_file)): 3984 self.assertEqual(main_file[i], lines[i])
3985 3986
3988 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3989 3990 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3991 """ 3992 3993 # Set the model. 3994 ds.models = [ 3995 MODEL_NOREX, 3996 MODEL_LM63, 3997 MODEL_CR72, 3998 MODEL_IT99 3999 ] 4000 4001 # Execute the script. 4002 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4003 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4004 4005 # The R20 keys. 4006 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4007 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4008 4009 # The 'No Rex' model checks. 4010 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4011 spin70 = return_spin(":70") 4012 spin71 = return_spin(":71") 4013 print("\n\nOptimised parameters:\n") 4014 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4015 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4016 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4017 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4018 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4019 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4020 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4021 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4022 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4023 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4024 4025 # The 'LM63' model checks. 4026 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4027 spin70 = return_spin(":70") 4028 spin71 = return_spin(":71") 4029 print("\n\nOptimised parameters:\n") 4030 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4031 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4032 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4033 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4034 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4035 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4036 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4037 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4038 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4039 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4040 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4041 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4042 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4043 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4044 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4045 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4046 4047 # The 'CR72' model checks. 4048 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4049 spin70 = return_spin(":70") 4050 spin71 = return_spin(":71") 4051 print("\n\nOptimised parameters:\n") 4052 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4053 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4054 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4055 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4056 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4057 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4058 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4059 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4060 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4061 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4062 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4063 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4064 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4065 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4066 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4067 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4068 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4069 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4070 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4071 4072
4074 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4075 4076 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4077 """ 4078 4079 # Set the model and numeric flag. 4080 ds.models = [ 4081 MODEL_NOREX, 4082 MODEL_CR72, 4083 MODEL_NS_CPMG_2SITE_EXPANDED 4084 ] 4085 ds.numeric_only = True 4086 4087 # Execute the script. 4088 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4089 4090 # The R20 keys. 4091 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4092 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4093 4094 # The 'No Rex' model checks. 4095 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4096 spin70 = return_spin(":70") 4097 spin71 = return_spin(":71") 4098 print("\n\nOptimised parameters:\n") 4099 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4100 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4101 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4102 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4103 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4104 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4105 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4106 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4107 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4108 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4109 4110 # The 'CR72' model checks. 4111 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4112 spin70 = return_spin(":70") 4113 spin71 = return_spin(":71") 4114 print("\n\nOptimised parameters:\n") 4115 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4116 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4117 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4118 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4119 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4120 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4121 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4122 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4123 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4124 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4125 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4126 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4127 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4128 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4129 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4130 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4131 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4132 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4133 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4134 4135 # The 'NS CPMG 2-site expanded' model checks. 4136 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4137 spin70 = return_spin(":70") 4138 spin71 = return_spin(":71") 4139 print("\n\nOptimised parameters:\n") 4140 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4141 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4142 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4143 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4144 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4145 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4146 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4147 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4148 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4149 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4150 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4151 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4152 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4153 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4154 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4155 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4156 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4157 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4158 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4159 4160 # The final data pipe checks. 4161 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4162 spin70 = return_spin(":70") 4163 spin71 = return_spin(":71") 4164 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4165 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4166 4167
4169 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4170 4171 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4172 """ 4173 4174 # Set the model. 4175 ds.models = [ 4176 MODEL_NOREX, 4177 MODEL_LM63, 4178 MODEL_CR72, 4179 MODEL_IT99 4180 ] 4181 4182 # Execute the script. 4183 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4184 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4185 4186 # The R20 keys. 4187 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4188 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4189 4190 # The 'No Rex' model checks. 4191 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4192 spin70 = return_spin(":70") 4193 spin71 = return_spin(":71") 4194 print("\n\nOptimised parameters:\n") 4195 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4196 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4197 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4198 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4199 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4200 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4201 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4202 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4203 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4204 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4205 4206 # The 'LM63' model checks. 4207 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4208 spin70 = return_spin(":70") 4209 spin71 = return_spin(":71") 4210 print("\n\nOptimised parameters:\n") 4211 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4212 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4213 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4214 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4215 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4216 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4217 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4218 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4219 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4220 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4221 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4222 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4223 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4224 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4225 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4226 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4227 4228 # The 'CR72' model checks. 4229 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4230 spin70 = return_spin(":70") 4231 spin71 = return_spin(":71") 4232 print("\n\nOptimised parameters:\n") 4233 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4234 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4235 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4236 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4237 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4238 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4239 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4240 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4241 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4242 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4243 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4244 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4245 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4246 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4247 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4248 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4249 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4250 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4251 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4252 4253
4255 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4256 4257 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4258 """ 4259 4260 # Set the model. 4261 ds.models = [ 4262 MODEL_R2EFF, 4263 MODEL_NOREX, 4264 MODEL_CR72, 4265 MODEL_NS_CPMG_2SITE_EXPANDED 4266 ] 4267 4268 # Execute the script. 4269 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4270 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4271 4272 # The R20 keys. 4273 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4274 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4275 4276 # The 'No Rex' model checks. 4277 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4278 spin4 = return_spin(":4") 4279 spin70 = return_spin(":70") 4280 spin71 = return_spin(":71") 4281 print("\n\nOptimised parameters:\n") 4282 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4283 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4284 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4285 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4286 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4287 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4288 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4289 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4290 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4291 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4292 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4293 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4294 4295 # The 'CR72' model checks. 4296 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4297 spin4 = return_spin(":4") 4298 spin70 = return_spin(":70") 4299 spin71 = return_spin(":71") 4300 print("\n\nOptimised parameters:\n") 4301 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4302 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4303 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4304 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4305 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4306 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4307 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4308 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4309 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4310 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4311 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4312 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4313 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4314 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4315 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4316 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4317 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4318 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4319 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4320 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4321 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4322 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4323 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4324 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4325 4326
4328 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4329 4330 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4331 """ 4332 4333 # Base data setup. 4334 self.setup_hansen_cpmg_data(model='CR72') 4335 4336 # Alias the spins. 4337 spin70 = return_spin(":70") 4338 spin71 = return_spin(":71") 4339 4340 # The R20 keys. 4341 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4342 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4343 4344 # Set the initial parameter values. 4345 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4346 spin70.pA = 0.9 4347 spin70.dw = 6.0 4348 spin70.kex = 1500.0 4349 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4350 spin71.pA = 0.9 4351 spin71.dw = 4.0 4352 spin71.kex = 1900.0 4353 4354 # Low precision optimisation. 4355 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4356 4357 # Printout. 4358 print("\n\nOptimised parameters:\n") 4359 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4360 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4361 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4362 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4363 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4364 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4365 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4366 4367 # Checks for residue :70. 4368 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4369 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4370 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4371 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4372 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4373 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4374 4375 # Checks for residue :71. 4376 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4377 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4378 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4379 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4380 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4381 4382 # Test the conversion to k_AB from kex and pA. 4383 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4384 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4385 4386 # Test the conversion to k_BA from kex and pA. 4387 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4388 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4389 4390
4392 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4393 4394 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4395 """ 4396 4397 # Base data setup. 4398 self.setup_hansen_cpmg_data(model='CR72 full') 4399 4400 # Alias the spins. 4401 spin70 = return_spin(":70") 4402 spin71 = return_spin(":71") 4403 4404 # The R20 keys. 4405 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4406 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4407 4408 # Set the initial parameter values. 4409 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4410 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4411 spin70.pA = 0.9 4412 spin70.dw = 6.0 4413 spin70.kex = 1500.0 4414 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4415 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4416 spin71.pA = 0.9 4417 spin71.dw = 4.0 4418 spin71.kex = 1900.0 4419 4420 # Low precision optimisation. 4421 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4422 4423 # Printout. 4424 print("\n\nOptimised parameters:\n") 4425 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4426 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4427 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4428 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4429 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4430 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4431 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4432 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4433 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4434 4435 # Checks for residue :70. 4436 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4437 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4438 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4439 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4440 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4441 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4442 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4443 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4444 4445 # Checks for residue :71. 4446 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4447 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4448 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4449 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4450 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4451 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4452 4453 # Test the conversion to k_AB from kex and pA. 4454 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4455 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4456 4457 # Test the conversion to k_BA from kex and pA. 4458 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4459 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4460 4461
4463 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4464 4465 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4466 """ 4467 4468 # Base data setup. 4469 self.setup_hansen_cpmg_data(model='IT99') 4470 4471 # Alias the spins. 4472 spin70 = return_spin(":70") 4473 spin71 = return_spin(":71") 4474 4475 # The R20 keys. 4476 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4477 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4478 4479 # Set the initial parameter values. 4480 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4481 spin70.dw = 10.0 4482 spin70.pA = 0.5 4483 spin70.tex = 1000.09 4484 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4485 spin71.dw = 10.0 4486 spin71.pA = 0.95 4487 spin71.tex = 0.1 4488 4489 # Low precision optimisation. 4490 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4491 4492 # Printout. 4493 print("\n\nOptimised parameters:\n") 4494 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4495 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4496 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4497 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4498 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4499 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4500 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4501 4502 # Checks for residue :70. 4503 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4504 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4505 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4506 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4507 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4508 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4509 4510 # Checks for residue :71. 4511 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4512 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4513 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4514 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4515 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4516 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4517 4518
4520 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4521 4522 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4523 """ 4524 4525 # Base data setup. 4526 self.setup_hansen_cpmg_data(model='LM63') 4527 4528 # Alias the spins. 4529 spin70 = return_spin(":70") 4530 spin71 = return_spin(":71") 4531 4532 # The R20 keys. 4533 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4534 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4535 4536 # Set the initial parameter values. 4537 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4538 spin70.phi_ex = 0.3 4539 spin70.kex = 5000.0 4540 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4541 spin71.phi_ex = 0.1 4542 spin71.kex = 2500.0 4543 4544 # Low precision optimisation. 4545 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4546 4547 # Printout. 4548 print("\n\nOptimised parameters:\n") 4549 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4550 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4551 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4552 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4553 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4554 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4555 4556 # Checks for residue :70. 4557 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4558 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4559 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4560 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4561 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4562 4563 # Checks for residue :71. 4564 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4565 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4566 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4567 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4568 4569
4571 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4572 4573 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4574 """ 4575 4576 # Base data setup. 4577 self.setup_hansen_cpmg_data(model='LM63 3-site') 4578 4579 # Alias the spins. 4580 spin70 = return_spin(":70") 4581 spin71 = return_spin(":71") 4582 4583 # The R20 keys. 4584 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4585 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4586 4587 ## Set the initial parameter values. 4588 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4589 spin70.phi_ex_B = 0.14872003058250227 4590 spin70.phi_ex_C = 0.1319419923472704 4591 spin70.kB = 4103.672910444741 4592 spin70.kC = 7029.001690726248 4593 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4594 spin71.phi_ex_B = 0.04013553485505605 4595 spin71.phi_ex_C = 0.020050748406928887 4596 spin71.kB = 4045.3007136121364 4597 spin71.kC = 3586.38798270774 4598 4599 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4600 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4601 4602 # Low precision optimisation. 4603 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4604 4605 # Printout. 4606 print("\n\nOptimised parameters:\n") 4607 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4608 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4609 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4610 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4611 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4612 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4613 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4614 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4615 4616 # Checks for residue :70. 4617 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4618 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4619 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4620 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4621 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4622 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4623 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4624 4625 # Checks for residue :71. 4626 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4627 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4628 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4629 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4630 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4631 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4632 4633
4635 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4636 4637 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4638 """ 4639 4640 # Base data setup. 4641 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4642 4643 # Alias the spins. 4644 spin70 = return_spin(":70") 4645 spin71 = return_spin(":71") 4646 4647 # The R20 keys. 4648 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4649 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4650 4651 # Set the initial parameter values. 4652 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4653 spin70.pA = 0.9897754407 4654 spin70.dw = 5.642418428 4655 spin70.kex = 1743.666375 4656 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4657 spin71.pA = 0.9968032899 4658 spin71.dw = 4.577891393 4659 spin71.kex = 1830.044597 4660 4661 # Low precision optimisation. 4662 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4663 4664 # Printout. 4665 print("\n\nOptimised parameters:\n") 4666 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4667 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4668 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4669 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4670 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4671 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4672 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4673 4674 # Checks for residue :70. 4675 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4676 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4677 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4678 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4679 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4680 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4681 4682 # Checks for residue :71. 4683 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4684 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4685 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4686 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4687 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4688 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4689 4690 # Test the conversion to k_AB from kex and pA. 4691 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4692 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4693 4694 # Test the conversion to k_BA from kex and pA. 4695 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4696 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4697 4698
4700 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4701 4702 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4703 """ 4704 4705 # Base data setup. 4706 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4707 4708 # Alias the spins. 4709 spin70 = return_spin(":70") 4710 spin71 = return_spin(":71") 4711 4712 # The R20 keys. 4713 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4714 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4715 4716 # Set the initial parameter values. 4717 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4718 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4719 spin70.pA = 0.9884781357 4720 spin70.dw = 5.456507396 4721 spin70.kex = 1906.521189 4722 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4723 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4724 spin71.pA = 0.986709616684097 4725 spin71.dw = 2.09245158280905 4726 spin71.kex = 2438.2766211401 4727 4728 # Low precision optimisation. 4729 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4730 4731 # Printout. 4732 print("\n\nOptimised parameters:\n") 4733 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4734 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4735 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4736 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4737 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4738 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4739 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4740 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4741 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4742 4743 # Checks for residue :70. 4744 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4745 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4746 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4747 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4748 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4749 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4750 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4751 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4752 4753 # Checks for residue :71. 4754 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4755 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4756 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4757 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4758 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4759 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4760 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4761 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4762 4763 # Test the conversion to k_AB from kex and pA. 4764 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4765 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4766 4767 # Test the conversion to k_BA from kex and pA. 4768 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4769 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4770 4771
4773 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4774 4775 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4776 """ 4777 4778 # Base data setup. 4779 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4780 4781 # Alias the spins. 4782 spin70 = return_spin(":70") 4783 spin71 = return_spin(":71") 4784 4785 # The R20 keys. 4786 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4787 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4788 4789 # Set the initial parameter values. 4790 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4791 spin70.pA = 0.9 4792 spin70.dw = 6.0 4793 spin70.kex = 1500.0 4794 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4795 spin71.pA = 0.9 4796 spin71.dw = 4.0 4797 spin71.kex = 1900.0 4798 4799 # Low precision optimisation. 4800 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4801 4802 # Printout. 4803 print("\n\nOptimised parameters:\n") 4804 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4805 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4806 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4807 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4808 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4809 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4810 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4811 4812 # Checks for residue :70. 4813 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4814 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4815 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4816 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4817 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4818 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4819 4820 # Checks for residue :71. 4821 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4822 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4823 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4824 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4825 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4826 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4827 4828 # Test the conversion to k_AB from kex and pA. 4829 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4830 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4831 4832 # Test the conversion to k_BA from kex and pA. 4833 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4834 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4835 4836
4838 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4839 4840 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4841 """ 4842 4843 # Base data setup. 4844 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4845 4846 # Alias the spins. 4847 spin70 = return_spin(":70") 4848 spin71 = return_spin(":71") 4849 4850 # The R20 keys. 4851 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4852 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4853 4854 # Set the initial parameter values. 4855 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4856 spin70.pA = 0.9897519798 4857 spin70.dw = 5.644862195 4858 spin70.kex = 1723.820567 4859 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4860 spin71.pA = 0.9968032899 4861 spin71.dw = 4.577891393 4862 spin71.kex = 1830.044597 4863 4864 # Low precision optimisation. 4865 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4866 4867 # Printout. 4868 print("\n\nOptimised parameters:\n") 4869 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4870 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4871 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4872 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4873 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4874 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4875 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4876 4877 # Checks for residue :70. 4878 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4879 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4880 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4881 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4882 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4883 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4884 4885 # Checks for residue :71. 4886 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4887 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4888 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4889 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4890 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4891 4892 # Test the conversion to k_AB from kex and pA. 4893 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4894 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4895 4896 # Test the conversion to k_BA from kex and pA. 4897 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4898 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4899 4900
4902 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4903 4904 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4905 """ 4906 4907 # Base data setup. 4908 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4909 4910 # Alias the spins. 4911 spin70 = return_spin(":70") 4912 spin71 = return_spin(":71") 4913 4914 # The R20 keys. 4915 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4916 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4917 4918 # Set the initial parameter values. 4919 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4920 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4921 spin70.pA = 0.987648082613451 4922 spin70.dw = 5.30679853807572 4923 spin70.kex = 2033.25380420666 4924 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4925 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4926 spin71.pA = 0.992258541625787 4927 spin71.dw = 2.75140650899058 4928 spin71.kex = 2106.60885247431 4929 4930 # Low precision optimisation. 4931 self.interpreter.minimise.calculate() 4932 4933 # Checks for residue :70. 4934 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4935 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4936 4937
4938 - def test_hansen_cpmgfit_input(self):
4939 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4940 4941 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4942 """ 4943 4944 # Load the R2eff results file. 4945 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4946 self.interpreter.results.read(file_name) 4947 self.interpreter.deselect.spin(':4') 4948 4949 # Set up the model. 4950 self.interpreter.relax_disp.select_model('LM63') 4951 4952 # Generate the input files. 4953 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4954 4955 # What the files should contain. 4956 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4957 spin1 = [ 4958 "title :70@N\n", 4959 "fields 2 11.7432964915 18.7892743865\n", 4960 "function CPMG\n", 4961 "R2 1 10 20\n", 4962 "Rex 0 100.0 100\n", 4963 "Tau 0 10.0 100\n", 4964 "xmgr\n", 4965 "@ xaxis label \"1/tcp (1/ms)\"\n", 4966 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4967 "@ xaxis ticklabel format decimal\n", 4968 "@ yaxis ticklabel format decimal\n", 4969 "@ xaxis ticklabel char size 0.8\n", 4970 "@ yaxis ticklabel char size 0.8\n", 4971 "@ world xmin 0.0\n", 4972 "data\n", 4973 "0.133333 16.045541 0.310925 11.743296 \n", 4974 "0.266667 14.877925 0.303217 11.743296 \n", 4975 "0.400000 14.357820 0.299894 11.743296 \n", 4976 "0.533333 12.664495 0.289532 11.743296 \n", 4977 "0.666667 12.363205 0.287760 11.743296 \n", 4978 "0.800000 11.092532 0.280514 11.743296 \n", 4979 "0.933333 10.566090 0.277619 11.743296 \n", 4980 "1.066667 9.805807 0.273544 11.743296 \n", 4981 "1.200000 9.564301 0.272276 11.743296 \n", 4982 "1.333333 9.015634 0.269442 11.743296 \n", 4983 "1.466667 8.607765 0.267375 11.743296 \n", 4984 "1.600000 8.279997 0.265740 11.743296 \n", 4985 "1.733333 8.474536 0.266708 11.743296 \n", 4986 "1.866667 8.158973 0.265141 11.743296 \n", 4987 "2.000000 7.988631 0.264304 11.743296 \n", 4988 "0.133333 22.224914 0.166231 18.789274 \n", 4989 "0.266667 21.230874 0.162377 18.789274 \n", 4990 "0.400000 20.603704 0.160017 18.789274 \n", 4991 "0.533333 20.327797 0.158996 18.789274 \n", 4992 "0.666667 18.855377 0.153719 18.789274 \n", 4993 "0.800000 18.537531 0.152617 18.789274 \n", 4994 "0.933333 17.508069 0.149138 18.789274 \n", 4995 "1.066667 16.035604 0.144391 18.789274 \n", 4996 "1.200000 15.168192 0.141717 18.789274 \n", 4997 "1.333333 14.431802 0.139516 18.789274 \n", 4998 "1.466667 14.034137 0.138354 18.789274 \n", 4999 "1.600000 12.920148 0.135192 18.789274 \n", 5000 "1.733333 12.653673 0.134456 18.789274 \n", 5001 "1.866667 12.610864 0.134338 18.789274 \n", 5002 "2.000000 11.969303 0.132601 18.789274 \n" 5003 ] 5004 spin2 = [ 5005 "title :71@N\n", 5006 "fields 2 11.7432964915 18.7892743865\n", 5007 "function CPMG\n", 5008 "R2 1 10 20\n", 5009 "Rex 0 100.0 100\n", 5010 "Tau 0 10.0 100\n", 5011 "xmgr\n", 5012 "@ xaxis label \"1/tcp (1/ms)\"\n", 5013 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 5014 "@ xaxis ticklabel format decimal\n", 5015 "@ yaxis ticklabel format decimal\n", 5016 "@ xaxis ticklabel char size 0.8\n", 5017 "@ yaxis ticklabel char size 0.8\n", 5018 "@ world xmin 0.0\n", 5019 "data\n", 5020 "0.133333 7.044342 0.170035 11.743296 \n", 5021 "0.266667 6.781033 0.169228 11.743296 \n", 5022 "0.400000 6.467623 0.168279 11.743296 \n", 5023 "0.533333 6.333340 0.167876 11.743296 \n", 5024 "0.666667 6.323238 0.167846 11.743296 \n", 5025 "0.800000 6.005245 0.166902 11.743296 \n", 5026 "0.933333 5.767052 0.166203 11.743296 \n", 5027 "1.066667 5.476968 0.165361 11.743296 \n", 5028 "1.200000 5.469949 0.165341 11.743296 \n", 5029 "1.333333 5.295113 0.164838 11.743296 \n", 5030 "1.466667 5.435648 0.165242 11.743296 \n", 5031 "1.600000 5.410400 0.165169 11.743296 \n", 5032 "1.733333 5.437554 0.165247 11.743296 \n", 5033 "1.866667 5.176844 0.164501 11.743296 \n", 5034 "2.000000 5.227232 0.164644 11.743296 \n", 5035 "0.133333 11.530903 0.081928 18.789274 \n", 5036 "0.266667 10.983094 0.081041 18.789274 \n", 5037 "0.400000 10.512403 0.080294 18.789274 \n", 5038 "0.533333 9.984805 0.079473 18.789274 \n", 5039 "0.666667 9.573163 0.078845 18.789274 \n", 5040 "0.800000 9.178810 0.078253 18.789274 \n", 5041 "0.933333 8.935719 0.077893 18.789274 \n", 5042 "1.066667 8.610147 0.077416 18.789274 \n", 5043 "1.200000 8.353778 0.077045 18.789274 \n", 5044 "1.333333 8.173729 0.076787 18.789274 \n", 5045 "1.466667 8.091607 0.076670 18.789274 \n", 5046 "1.600000 7.706420 0.076126 18.789274 \n", 5047 "1.733333 7.709125 0.076129 18.789274 \n", 5048 "1.866667 7.610856 0.075992 18.789274 \n", 5049 "2.000000 7.552584 0.075911 18.789274 \n", 5050 ] 5051 5052 # Check the batch file. 5053 print("\nChecking the batch file.") 5054 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 5055 lines = file.readlines() 5056 file.close() 5057 for i in range(len(lines)): 5058 self.assertEqual(batch_file[i], lines[i]) 5059 5060 # Check spin :70@N. 5061 print("\nChecking the spin :70@N input file.") 5062 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5063 lines = file.readlines() 5064 file.close() 5065 for i in range(len(spin1)): 5066 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5067 for i in range(len(lines)): 5068 self.assertEqual(spin1[i], lines[i]) 5069 5070 # Check spin :71@N. 5071 print("\nChecking the spin :71@N input file.") 5072 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5073 lines = file.readlines() 5074 file.close() 5075 for i in range(len(lines)): 5076 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5077 for i in range(len(spin2)): 5078 self.assertEqual(spin2[i], lines[i])
5079 5080
5082 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5083 5084 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5085 5086 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5087 5088 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5089 - pA = 0.965402506690231, 5090 - dw = 0.805197170133360, 5091 - dwH = -0.595536627771890, 5092 - kex = 569.003663067619868, 5093 - chi2 = 9.297671357952812. 5094 """ 5095 5096 # Base data setup. 5097 self.setup_korzhnev_2005_data(data_list=['DQ']) 5098 5099 # Alias the spin. 5100 spin = return_spin(":9@N") 5101 5102 # The R20 keys. 5103 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5104 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5105 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5106 5107 # Set the initial parameter values. 5108 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5109 spin.pA = 0.965638501551899 5110 spin.dw = 2.8537583461577 5111 spin.dwH = -0.387633062766635 5112 spin.kex = 573.704033851592 5113 5114 # Low precision optimisation. 5115 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5116 5117 # Monte Carlo simulations. 5118 self.interpreter.monte_carlo.setup(number=3) 5119 self.interpreter.monte_carlo.create_data(method='back_calc') 5120 self.interpreter.monte_carlo.initial_values() 5121 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5122 self.interpreter.monte_carlo.error_analysis() 5123 5124 # Plot the dispersion curves. 5125 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5126 5127 # Save the results. 5128 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5129 5130 # Printout. 5131 print("\n\nOptimised parameters:\n") 5132 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5133 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5134 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5135 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5136 print("%-20s %20.15g" % ("pA", spin.pA)) 5137 print("%-20s %20.15g" % ("dw", spin.dw)) 5138 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5139 print("%-20s %20.15g" % ("kex", spin.kex)) 5140 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5141 5142 # Checks for residue :9. 5143 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5144 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5145 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5146 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5147 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5148 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5149 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5150 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5151 5152
5154 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5155 5156 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5157 5158 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5159 5160 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5161 - pA = 0.930027999814003, 5162 - dw = 4.338620619954370, 5163 - dwH = -0.274250775560818, 5164 - kex = 344.613362916544475, 5165 - chi2 = 10.367733168217050. 5166 """ 5167 5168 # Base data setup. 5169 self.setup_korzhnev_2005_data(data_list=['MQ']) 5170 5171 # Alias the spin. 5172 spin = return_spin(":9@N") 5173 5174 # The R20 keys. 5175 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5176 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5177 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5178 5179 # Set the initial parameter values. 5180 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5181 spin.pA = 0.930083249288083 5182 spin.dw = 4.33890689462363 5183 spin.dwH = -0.274316585638047 5184 spin.kex = 344.329651956132 5185 5186 # Low precision optimisation. 5187 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5188 5189 # Monte Carlo simulations. 5190 self.interpreter.monte_carlo.setup(number=3) 5191 self.interpreter.monte_carlo.create_data(method='back_calc') 5192 self.interpreter.monte_carlo.initial_values() 5193 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5194 self.interpreter.monte_carlo.error_analysis() 5195 5196 # Plot the dispersion curves. 5197 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5198 5199 # Save the results. 5200 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5201 5202 # Printout. 5203 print("\n\nOptimised parameters:\n") 5204 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5205 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5206 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5207 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5208 print("%-20s %20.15g" % ("pA", spin.pA)) 5209 print("%-20s %20.15g" % ("dw", spin.dw)) 5210 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5211 print("%-20s %20.15g" % ("kex", spin.kex)) 5212 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5213 5214 # Checks for residue :9. 5215 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5216 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5217 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5218 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5219 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5220 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5221 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5222 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5223 5224
5226 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5227 5228 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5229 5230 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5231 5232 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5233 - pA = 0.950003458294991, 5234 - dw = 4.358402855315123, 5235 - kex = 429.906473361926999, 5236 - chi2 = 17.393331915567252. 5237 """ 5238 5239 # Base data setup. 5240 self.setup_korzhnev_2005_data(data_list=['SQ']) 5241 5242 # Alias the spin. 5243 spin = return_spin(":9@N") 5244 5245 # The R20 keys. 5246 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5247 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5248 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5249 5250 # Set the initial parameter values. 5251 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5252 spin.pA = 0.950310172115387 5253 spin.dw = 4.356737157889636 5254 spin.kex = 433.176323890829849 5255 5256 # Low precision optimisation. 5257 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5258 5259 # Monte Carlo simulations. 5260 self.interpreter.monte_carlo.setup(number=3) 5261 self.interpreter.monte_carlo.create_data(method='back_calc') 5262 self.interpreter.monte_carlo.initial_values() 5263 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5264 self.interpreter.monte_carlo.error_analysis() 5265 5266 # Plot the dispersion curves. 5267 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5268 5269 # Save the results. 5270 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5271 5272 # Printout. 5273 print("\n\nOptimised parameters:\n") 5274 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5275 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5276 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5277 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5278 print("%-20s %20.15g" % ("pA", spin.pA)) 5279 print("%-20s %20.15g" % ("dw", spin.dw)) 5280 print("%-20s %20.15g" % ("kex", spin.kex)) 5281 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5282 5283 # Checks for residue :9. 5284 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5285 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5286 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5287 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5288 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5289 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5290 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5291 5292
5294 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5295 5296 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5297 5298 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5299 5300 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5301 - pA = 0.942452612380140, 5302 - dw = 0.858972784230892, 5303 - dwH = 0.087155962730608, 5304 - kex = 373.219151384798920, 5305 - chi2 = 23.863208106025152. 5306 """ 5307 5308 # Base data setup. 5309 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5310 5311 # Alias the spin. 5312 spin = return_spin(":9@N") 5313 5314 # The R20 keys. 5315 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5316 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5317 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5318 5319 # Set the initial parameter values. 5320 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5321 spin.pA = 0.942457332074014 5322 spin.dw = 0.850592422908884 5323 spin.dwH = 0.0881272284455416 5324 spin.kex = 372.745483351305 5325 5326 # Low precision optimisation. 5327 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5328 5329 # Monte Carlo simulations. 5330 self.interpreter.monte_carlo.setup(number=3) 5331 self.interpreter.monte_carlo.create_data(method='back_calc') 5332 self.interpreter.monte_carlo.initial_values() 5333 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5334 self.interpreter.monte_carlo.error_analysis() 5335 5336 # Plot the dispersion curves. 5337 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5338 5339 # Save the results. 5340 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5341 5342 # Printout. 5343 print("\n\nOptimised parameters:\n") 5344 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5345 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5346 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5347 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5348 print("%-20s %20.15g" % ("pA", spin.pA)) 5349 print("%-20s %20.15g" % ("dw", spin.dw)) 5350 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5351 print("%-20s %20.15g" % ("kex", spin.kex)) 5352 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5353 5354 # Checks for residue :9. 5355 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5356 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5357 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5358 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5359 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5360 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5361 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5362 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5363 5364
5366 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5367 5368 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5369 5370 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5371 5372 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5373 - pA = 0.936911090448340, 5374 - dw = 4.325314846914845, 5375 - dwH = -0.213870168665628, 5376 - kex = 487.361914835074117, 5377 - chi2 = 14.870371897291138. 5378 """ 5379 5380 # Base data setup. 5381 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5382 5383 # Alias the spin. 5384 spin = return_spin(":9@N") 5385 5386 # The R20 keys. 5387 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5388 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5389 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5390 5391 # Set the initial parameter values. 5392 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5393 spin.pA = 0.936884348941701 5394 spin.dw = 4.326454531583964 5395 spin.dwH = -0.214026093221782 5396 spin.kex = 487.043592705469223 5397 5398 # Low precision optimisation. 5399 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5400 5401 # Monte Carlo simulations. 5402 self.interpreter.monte_carlo.setup(number=3) 5403 self.interpreter.monte_carlo.create_data(method='back_calc') 5404 self.interpreter.monte_carlo.initial_values() 5405 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5406 self.interpreter.monte_carlo.error_analysis() 5407 5408 # Plot the dispersion curves. 5409 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5410 5411 # Save the results. 5412 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5413 5414 # Printout. 5415 print("\n\nOptimised parameters:\n") 5416 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5417 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5418 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5419 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5420 print("%-20s %20.15g" % ("pA", spin.pA)) 5421 print("%-20s %20.15g" % ("dw", spin.dw)) 5422 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5423 print("%-20s %20.15g" % ("kex", spin.kex)) 5424 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5425 5426 # Checks for residue :9. 5427 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5428 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5429 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5430 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5431 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5432 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5433 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5434 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5435 5436
5438 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5439 5440 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5441 5442 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5443 5444 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5445 - pA = 0.946949480545876, 5446 - dwH = -0.265279672133308, 5447 - kex = 406.548178869750700, 5448 - chi2 = 50.400680290545026. 5449 """ 5450 5451 # Base data setup. 5452 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5453 5454 # Alias the spin. 5455 spin = return_spin(":9@N") 5456 5457 # The R20 keys. 5458 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5459 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5460 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5461 5462 # Set the initial parameter values. 5463 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5464 spin.pA = 0.946990967372467 5465 spin.dwH = -0.265308128403529 5466 spin.kex = 406.843250675648 5467 5468 # Low precision optimisation. 5469 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5470 5471 # Monte Carlo simulations. 5472 self.interpreter.monte_carlo.setup(number=3) 5473 self.interpreter.monte_carlo.create_data(method='back_calc') 5474 self.interpreter.monte_carlo.initial_values() 5475 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5476 self.interpreter.monte_carlo.error_analysis() 5477 5478 # Plot the dispersion curves. 5479 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5480 5481 # Save the results. 5482 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5483 5484 # Printout. 5485 print("\n\nOptimised parameters:\n") 5486 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5487 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5488 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5489 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5490 print("%-20s %20.15g" % ("pA", spin.pA)) 5491 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5492 print("%-20s %20.15g" % ("kex", spin.kex)) 5493 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5494 5495 # Checks for residue :9. 5496 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5497 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5498 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5499 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5500 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5501 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5502 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5503 5504
5506 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5507 5508 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5509 5510 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5511 5512 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5513 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5514 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5515 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5516 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5517 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5518 - pA = 0.943125351763911, 5519 - dw = 4.421827493809807, 5520 - dwH = -0.272637034755752, 5521 - kex = 360.609744568697238, 5522 - chi2 = 162.589570340050813. 5523 """ 5524 5525 # Base data setup. 5526 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5527 5528 # Alias the spin. 5529 spin = return_spin(":9@N") 5530 5531 # The R20 keys. 5532 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5533 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5534 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5535 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5536 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5537 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5538 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5539 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5540 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5541 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5542 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5543 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5544 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5545 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5546 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5547 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5548 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5549 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5550 5551 # Set the initial parameter values. 5552 spin.r2 = { 5553 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5554 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5555 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5556 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5557 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5558 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5559 } 5560 spin.pA = 0.943129019477673 5561 spin.dw = 4.42209952545181 5562 spin.dwH = -0.27258970590969 5563 spin.kex = 360.516132791038 5564 5565 # Low precision optimisation. 5566 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5567 5568 # Monte Carlo simulations. 5569 self.interpreter.monte_carlo.setup(number=3) 5570 self.interpreter.monte_carlo.create_data(method='back_calc') 5571 self.interpreter.monte_carlo.initial_values() 5572 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5573 self.interpreter.monte_carlo.error_analysis() 5574 5575 # Plot the dispersion curves. 5576 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5577 5578 # Save the results. 5579 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5580 5581 # Printout. 5582 print("\n\nOptimised parameters:\n") 5583 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5584 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5585 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5586 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5587 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5588 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5589 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5590 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5591 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5592 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5593 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5594 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5595 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5596 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5597 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5598 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5599 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5600 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5601 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5602 print("%-20s %20.15g" % ("pA", spin.pA)) 5603 print("%-20s %20.15g" % ("dw", spin.dw)) 5604 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5605 print("%-20s %20.15g" % ("kex", spin.kex)) 5606 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5607 5608 # Checks for residue :9. 5609 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5610 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5611 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5612 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5613 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5614 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5615 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5616 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5617 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5618 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5619 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5620 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5621 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5622 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5623 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5624 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5625 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5626 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5627 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5628 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5629 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5630 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5631 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5632 5633
5635 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5636 5637 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5638 5639 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5640 5641 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5642 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5643 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5644 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5645 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5646 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5647 - pA = 0.943125351763911, 5648 - dw = 4.421827493809807, 5649 - dwH = -0.272637034755752, 5650 - kex = 360.609744568697238, 5651 - chi2 = 162.589570340050813. 5652 """ 5653 5654 # Base data setup. 5655 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5656 5657 # Alias the spin. 5658 spin = return_spin(":9@N") 5659 5660 # The R20 keys. 5661 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5662 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5663 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5664 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5665 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5666 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5667 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5668 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5669 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5670 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5671 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5672 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5673 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5674 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5675 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5676 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5677 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5678 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5679 5680 # Set the initial parameter values. 5681 spin.r2 = { 5682 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5683 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5684 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5685 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5686 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5687 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5688 } 5689 spin.pA = 0.943129019477673 5690 spin.dw = 4.42209952545181 5691 spin.dwH = -0.27258970590969 5692 spin.kex = 360.516132791038 5693 5694 # Calc the chi2 values at these parameters. 5695 self.interpreter.minimise.calculate(verbosity=1) 5696 5697 # Printout. 5698 print("\n\nOptimised parameters:\n") 5699 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5700 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5701 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5702 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5703 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5704 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5705 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5706 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5707 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5708 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5709 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5710 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5711 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5712 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5713 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5714 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5715 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5716 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5717 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5718 print("%-20s %20.15g" % ("pA", spin.pA)) 5719 print("%-20s %20.15g" % ("dw", spin.dw)) 5720 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5721 print("%-20s %20.15g" % ("kex", spin.kex)) 5722 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5723 5724 # Checks for residue :9. 5725 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5726 5727
5729 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5730 5731 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5732 5733 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5734 5735 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5736 - 0.483 0.89623903 2.4503699912708878 5737 - 0.545 1.1694838 5738 - 0.545 1.1761503 5739 - 0.622 1.294 5740 - 0.669 1.5176493 5741 - 0.722 1.6238791 5742 - 0.813 1.9395758 5743 - 1.011 2.3558415 10.547000429321157 5744 """ 5745 5746 # Base data setup. 5747 model = 'TSMFK01' 5748 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5749 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5750 5751 # Alias the spins. 5752 res61L = cdp.mol[0].res[0].spin[0] 5753 5754 # The R20 keys. 5755 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5756 5757 # Set the initial parameter values. 5758 res61L.r2a = {r20_key1: 8.0} 5759 res61L.dw = 6.5 5760 res61L.k_AB = 2.5 5761 5762 # Low precision optimisation. 5763 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5764 5765 # Start testing all possible combinations of graphs. 5766 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5767 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5768 interpolate_types = [INTERPOLATE_DISP] 5769 5770 # Write to temp folder. 5771 result_dir_name = ds.tmpdir 5772 result_folders = [model] 5773 spin_id = ":61@N" 5774 5775 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5776 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5777 5778 for result_folder in result_folders: 5779 for y_axis in y_axis_types: 5780 for x_axis in x_axis_types: 5781 for interpolate in interpolate_types: 5782 # Determine file name: 5783 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5784 5785 # Make the file name. 5786 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5787 5788 # Write the curves. 5789 dir = result_dir_name+sep+result_folder 5790 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5791 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5792 5793 # Get the file path. 5794 file_path = get_file_path(file_name, dir) 5795 5796 # Test the plot file exists. 5797 print("Testing file access to graph: %s"%file_path) 5798 self.assert_(access(file_path, F_OK)) 5799 5800 # Now open, and compare content, line by line. 5801 file_prod = open(file_path) 5802 lines_prod = file_prod.readlines() 5803 file_prod.close() 5804 5805 # Define file to compare against. 5806 dir_comp = data_path+sep+result_folder 5807 file_path_comp = get_file_path(file_name, dir_comp) 5808 file_comp = open(file_path_comp) 5809 lines_comp = file_comp.readlines() 5810 file_comp.close() 5811 5812 ## Assert number of lines is equal. 5813 self.assertEqual(len(lines_prod), len(lines_comp)) 5814 for j in range(len(lines_prod)): 5815 # Make the string test 5816 first_char = lines_prod[j][0] 5817 if first_char in ["@", "&"]: 5818 self.assertEqual(lines_prod[j], lines_comp[j]) 5819 else: 5820 # Split string in x, y, error. 5821 # The error would change per run. 5822 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5823 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5824 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5825 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5826 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5827 5828
5830 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5831 5832 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5833 """ 5834 5835 # Base data setup. 5836 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5837 5838 # Alias the spins. 5839 res61L = cdp.mol[0].res[0].spin[0] 5840 5841 # The R20 keys. 5842 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5843 5844 # Set the initial parameter values. 5845 res61L.r2 = {r20_key1: 8.0} 5846 res61L.pA = 0.9 5847 res61L.dw = 6.0 5848 res61L.kex = 600.0 5849 5850 # Low precision optimisation. 5851 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5852 5853 # Printout. 5854 print("\n\nOptimised parameters:\n") 5855 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5856 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5857 print("%-20s %20.15g" % ("pA", res61L.pA)) 5858 print("%-20s %20.15g" % ("dw", res61L.dw)) 5859 print("%-20s %20.15g" % ("kex", res61L.kex)) 5860 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5861 5862 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5863 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5864 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5865 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5866 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5867 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5868 5869 # Test the conversion to k_AB from kex and pA. 5870 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5871 5872 # Test the conversion to k_BA from kex and pA. 5873 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5874 5875
5877 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5878 5879 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5880 """ 5881 5882 # Base data setup. 5883 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5884 5885 # Alias the spins. 5886 res61L = cdp.mol[0].res[0].spin[0] 5887 5888 # The R20 keys. 5889 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5890 5891 # Set the initial parameter values. 5892 res61L.r2a = {r20_key1: 8.0} 5893 res61L.r2b = {r20_key1: 105.0} 5894 res61L.pA = 0.9 5895 res61L.dw = 6.0 5896 res61L.kex = 500.0 5897 5898 # Low precision optimisation. 5899 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5900 5901 # Printout. 5902 print("\n\nOptimised parameters:\n") 5903 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5904 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5905 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5906 print("%-20s %20.15g" % ("pA", res61L.pA)) 5907 print("%-20s %20.15g" % ("dw", res61L.dw)) 5908 print("%-20s %20.15g" % ("kex", res61L.kex)) 5909 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5910 5911 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5912 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5913 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5914 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5915 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5916 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5917 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5918 5919
5921 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5922 5923 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5924 5925 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5926 5927 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5928 - 0.483 0.89623903 2.4503699912708878 5929 - 0.545 1.1694838 5930 - 0.545 1.1761503 5931 - 0.622 1.294 5932 - 0.669 1.5176493 5933 - 0.722 1.6238791 5934 - 0.813 1.9395758 5935 - 1.011 2.3558415 10.547000429321157 5936 """ 5937 5938 # Base data setup. 5939 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5940 5941 # Alias the spins. 5942 res61L = cdp.mol[0].res[0].spin[0] 5943 5944 # The R20 keys. 5945 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5946 5947 # Set the initial parameter values. 5948 res61L.r2a = {r20_key1: 8.0} 5949 res61L.dw = 6.5 5950 res61L.k_AB = 2.5 5951 5952 # Low precision optimisation. 5953 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5954 5955 # Printout. 5956 print("\n\nOptimised parameters:\n") 5957 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5958 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5959 print("%-20s %20.15g" % ("dw", res61L.dw)) 5960 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5961 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5962 5963 # Checks for residue :61. Reference values from paper 5964 5965 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5966 5967
5969 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5970 5971 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5972 5973 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5974 5975 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5976 5977 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5978 - k_AB = 11.3 +/- 0.7 s^-1, 5979 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5980 - R2 = 8.0 +/- 0.5 s^-1. 5981 5982 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5983 - k_AB = 10.55 +/- 0.08 s^-1, 5984 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5985 - R2 = 8.4 +/- 0.3 s^-1. 5986 5987 Conversion of paper results to relax results is performed by: 5988 5989 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5990 5991 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5992 5993 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5994 - 0.483 0.89623903 2.4503699912708878 5995 - 0.545 1.1694838 5996 - 0.545 1.1761503 5997 - 0.622 1.294 5998 - 0.669 1.5176493 5999 - 0.722 1.6238791 6000 - 0.813 1.9395758 6001 - 1.011 2.3558415 10.547000429321157 6002 """ 6003 6004 # Base data setup. 6005 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 6006 6007 # Alias the spins. 6008 res61L = cdp.mol[0].res[0].spin[0] 6009 6010 # The R20 keys. 6011 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 6012 6013 # Set the initial parameter values. 6014 res61L.r2a = {r20_key1: 8.0} 6015 res61L.dw = 6.5 6016 res61L.k_AB = 11.0 6017 6018 # Low precision optimisation. 6019 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6020 6021 # Printout. 6022 print("\n\nOptimised parameters:\n") 6023 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 6024 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 6025 print("%-20s %20.15g" % ("dw", res61L.dw)) 6026 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 6027 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 6028 6029 # Checks for residue :61. Reference values from paper 6030 6031 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 6032 self.assertAlmostEqual(res61L.dw, 6.41, 0) 6033 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6034 6035
6036 - def test_lm63_3site_synthetic(self):
6037 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 6038 6039 # The path to the data files. 6040 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 6041 6042 # Load the state file. 6043 self.interpreter.reset() 6044 self.interpreter.state.load(data_path+sep+'r2eff_values') 6045 6046 # A new data pipe. 6047 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 6048 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 6049 6050 # Set up the model data. 6051 self.interpreter.relax_disp.select_model(model='LM63 3-site') 6052 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 6053 self.interpreter.spin.isotope('15N') 6054 6055 # Alias the spins. 6056 spin1 = return_spin(":1") 6057 spin2 = return_spin(":2") 6058 6059 # The R20 keys. 6060 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6061 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6062 6063 # Manually set the parameter values. 6064 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6065 spin1.phi_ex_B = 0.1 6066 spin1.phi_ex_C = 0.5 6067 spin1.kB = 1500.0 6068 spin1.kC = 2500.0 6069 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6070 spin2.phi_ex_B = 0.1 6071 spin2.phi_ex_C = 0.5 6072 spin2.kB = 1500.0 6073 spin2.kC = 2500.0 6074 6075 # Low precision optimisation. 6076 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6077 6078 # Monte Carlo simulations. 6079 self.interpreter.monte_carlo.setup(number=3) 6080 self.interpreter.monte_carlo.create_data(method='back_calc') 6081 self.interpreter.monte_carlo.initial_values() 6082 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 6083 self.interpreter.monte_carlo.error_analysis() 6084 6085 # Save the results. 6086 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6087 6088 # The model checks. 6089 print("\n\nOptimised parameters:\n") 6090 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6091 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6092 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6093 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6094 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6095 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6096 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6097 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6098 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6099 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6100 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6101 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6102 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6103 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6104 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6105 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6106 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6107 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6108 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6109 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6110 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6111 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6112 6113
6114 - def test_m61_data_to_m61(self):
6115 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6116 6117 # Fixed time variable. 6118 ds.fixed = True 6119 6120 # Execute the script. 6121 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6122 6123 # The original parameters. 6124 i0 = [100000.0, 20000.0] 6125 r1rho_prime = [2.25, 24.0] 6126 pA = 0.7 6127 kex = 1000.0 6128 delta_omega = [1.0, 2.0] 6129 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6130 phi_ex = [] 6131 for i in range(2): 6132 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6133 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6134 6135 # Switch to the 'R2eff' model data pipe, then check for each spin. 6136 self.interpreter.pipe.switch('R2eff - relax_disp') 6137 spin_index = 0 6138 for spin, spin_id in spin_loop(return_id=True): 6139 # Printout. 6140 print("\nSpin %s." % spin_id) 6141 6142 # Check the fitted parameters. 6143 for i in range(len(keys)): 6144 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6145 6146 # Increment the spin index. 6147 spin_index += 1 6148 6149 # The R20 keys. 6150 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6151 6152 # Switch to the 'M61' model data pipe, then check for each spin. 6153 self.interpreter.pipe.switch('M61 - relax_disp') 6154 spin_index = 0 6155 for spin, spin_id in spin_loop(return_id=True): 6156 # Printout. 6157 print("\nSpin %s." % spin_id) 6158 6159 # Check the fitted parameters. 6160 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6161 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6162 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6163 6164 # Increment the spin index. 6165 spin_index += 1
6166 6167
6168 - def test_m61_exp_data_to_m61(self):
6169 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6170 6171 # Fixed time variable. 6172 ds.fixed = False 6173 6174 # Single spin optimisation. 6175 ds.single = True 6176 6177 # Execute the script. 6178 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6179 6180 # The original parameters. 6181 i0 = [100000.0, 20000.0] 6182 r1rho_prime = [2.25, 24.0] 6183 pA = 0.7 6184 kex = 1000.0 6185 delta_omega = [1.0, 2.0] 6186 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6187 phi_ex = [] 6188 for i in range(2): 6189 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6190 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6191 6192 # Switch to the 'R2eff' model data pipe, then check for each spin. 6193 self.interpreter.pipe.switch('R2eff - relax_disp') 6194 spin_index = 0 6195 for spin, spin_id in spin_loop(return_id=True): 6196 # Printout. 6197 print("\nSpin %s." % spin_id) 6198 6199 # Check the fitted parameters. 6200 for i in range(len(keys)): 6201 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6202 6203 # Increment the spin index. 6204 spin_index += 1 6205 6206 # The R20 keys. 6207 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6208 6209 # Switch to the 'M61' model data pipe, then check for each spin. 6210 self.interpreter.pipe.switch('M61 - relax_disp') 6211 spin_index = 0 6212 for spin, spin_id in spin_loop(return_id=True): 6213 # Printout. 6214 print("\nSpin %s." % spin_id) 6215 6216 # Check the fitted parameters. 6217 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6218 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6219 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6220 6221 # Increment the spin index. 6222 spin_index += 1
6223 6224
6225 - def test_m61b_data_to_m61b(self):
6226 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6227 6228 # Execute the script. 6229 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6230 6231 # The original parameters. 6232 i0 = [100000.0, 20000.0] 6233 r1rho_prime = [10.0, 24.0] 6234 pA = 0.95 6235 kex = 2000.0 6236 delta_omega = [1.0, 2.0] 6237 6238 # The R20 keys. 6239 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6240 6241 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6242 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6243 spin_index = 0 6244 for spin, spin_id in spin_loop(return_id=True): 6245 # Printout. 6246 print("\nSpin %s." % spin_id) 6247 6248 # Check the fitted parameters. 6249 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6250 self.assertAlmostEqual(spin.pA, pA, 2) 6251 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6252 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6253 6254 # Increment the spin index. 6255 spin_index += 1
6256 6257
6259 """Test that all models which can nest, have all their parameters converted.""" 6260 6261 # Set the experiment type. 6262 cdp.exp_type_list = EXP_TYPE_LIST 6263 6264 # Get info for all models. 6265 all_models_info = models_info(models=MODEL_LIST_FULL) 6266 6267 # Loop over all models. 6268 print("Printing the listed of nested models for each model.") 6269 print("#########################################") 6270 for model_info in all_models_info: 6271 print("%s"%model_info.model), 6272 print("<-"), 6273 nest_list = model_info.nest_list 6274 if nest_list == None: 6275 nest_list = ["None"] 6276 print(', '.join(map(str, nest_list))) 6277 6278 # Skip if there is no model to nest from. 6279 if nest_list == ["None"]: 6280 continue 6281 6282 # Assign params to variable. 6283 model_params = model_info.params 6284 6285 # Now loop over the nested models. 6286 for nested_model in nest_list: 6287 # Get the params for the nested model. 6288 nested_model_params = MODEL_PARAMS[nested_model] 6289 6290 # Get the dictionary of parameter conversion. 6291 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6292 6293 # Test the number of elements in the dictionary. 6294 self.assertEqual(len(par_dic), len(model_params)) 6295 6296 # Loop over dictionary. 6297 for param in par_dic: 6298 if param != par_dic[param]: 6299 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6300 self.assertNotEqual(par_dic[param], None)
6301 6302
6303 - def test_ns_mmq_3site(self):
6304 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6305 6306 # Execute the script. 6307 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6308 6309 # Check the chi-squared value. 6310 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6311 6312
6313 - def test_ns_mmq_3site_linear(self):
6314 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6315 6316 # Execute the script. 6317 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6318 6319 # Check the chi-squared value. 6320 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6321 6322
6323 - def test_ns_r1rho_3site(self):
6324 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6325 6326 # Execute the script. 6327 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6328 6329 # Check the chi-squared value. 6330 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6331 6332
6333 - def test_ns_r1rho_3site_linear(self):
6334 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6335 6336 # Execute the script. 6337 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6338 6339 # Check the chi-squared value. 6340 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6341 6342
6343 - def test_paul_schanda_nov_2015(self):
6344 """This test truncated private data which was provided by Paul Schanda. This systemtest uncovers some unfortunate problems when 6345 running an analysis and reading points by the R2eff method. 6346 """ 6347 6348 # Assign 6349 outdir = ds.tmpdir 6350 6351 # Execute the setup and creation of files. 6352 self.setup_paul_schanda_nov_2015(outdir=outdir) 6353 6354 # Minimum: Just read the sequence data, but this misses a lot of information. 6355 self.interpreter.sequence.read(file='residues.txt', res_num_col=1, dir=outdir) 6356 6357 # Open the settings file. 6358 set_file = open(outdir+sep+"exp_settings.txt") 6359 set_file_lines = set_file.readlines() 6360 6361 # Now load the data. 6362 for line in set_file_lines: 6363 if "#" in line[0]: 6364 continue 6365 6366 # Get data 6367 field, RF_field_strength_kHz, f_name = line.split() 6368 6369 # Assign data 6370 spec_id = f_name 6371 self.interpreter.relax_disp.exp_type(spectrum_id=spec_id, exp_type='R1rho') 6372 6373 # Set the spectrometer frequency 6374 self.interpreter.spectrometer.frequency(id=spec_id, frq=float(field), units='MHz') 6375 6376 # Is in kHz, som convert to Hz 6377 disp_frq = float(RF_field_strength_kHz)*1000 6378 6379 # Set The spin-lock field strength, nu1, in Hz 6380 self.interpreter.relax_disp.spin_lock_field(spectrum_id=spec_id, field=disp_frq) 6381 6382 # Read the R2eff data 6383 self.interpreter.relax_disp.r2eff_read(id=spec_id, file=f_name, dir=None, disp_frq=disp_frq, res_num_col=1, data_col=2, error_col=3) 6384 6385 # Is this necessary? The time, in seconds, of the relaxation period. 6386 #self.interpreter.relax_disp.relax_time(spectrum_id=spec_id, time=time_sl) 6387 6388 6389 # Check that the number of R2eff points is correct after dropping 1 datapoint for spin 51. 6390 r2eff_points = [] 6391 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6392 # Loop over the R2eff points 6393 for key in cur_spin.r2eff: 6394 value = cur_spin.r2eff[key] 6395 err = cur_spin.r2eff_err[key] 6396 r2eff_points.append(value) 6397 6398 # Test that values and errors are not nan. 6399 self.assert_(not isnan(value)) 6400 self.assert_(not isnan(err)) 6401 6402 6403 # Test the number of r2eff points. One is subtracted, due to one of the error values are "nan" in spin 51. 6404 self.assertEqual(len(r2eff_points), 2*(10+19)-1) 6405 6406 # Test stored value in the pipe. 6407 self.assertEqual(len(cdp.mol), 1) 6408 self.assertEqual(cdp.mol[0].name, None) 6409 self.assertEqual(len(cdp.mol[0].res), 2) 6410 6411 self.assertEqual(cdp.spectrometer_frq_count, 2) 6412 print cdp.spectrometer_frq_list 6413 self.assertEqual(cdp.spectrometer_frq_list, [600000000.0, 950000000.0]) 6414 self.assertEqual(cdp.exp_type_list, ['R1rho']) 6415 6416 # Test the number of frequencies. 6417 count_600 = 0 6418 count_950 = 0 6419 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 6420 if frq == cdp.spectrometer_frq_list[0]: 6421 count_600 += 1 6422 elif frq == cdp.spectrometer_frq_list[1]: 6423 count_950 += 1 6424 6425 # Assert the number of points 6426 self.assertEqual(count_600, 10) 6427 self.assertEqual(count_950, 19) 6428 6429 # Name the isotope for field strength scaling. 6430 self.interpreter.spin.isotope(isotope='15N') 6431 6432 # Now test that the plotting can be performed of just the raw data. 6433 self.assertRaises(RelaxError, self.interpreter.relax_disp.plot_disp_curves, dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6434 self.interpreter.relax_disp.select_model(model=MODEL_R2EFF) 6435 self.interpreter.relax_disp.plot_disp_curves(dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6436 6437 6438 # Number of grid search increments. If set to None, then the grid search will be turned off and the default parameter values will be used instead. 6439 #GRID_INC = None 6440 GRID_INC = 21 6441 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6442 MC_NUM = 3 6443 # Model selection technique. 6444 MODSEL = 'AIC' 6445 # Which models to analyse ? 6446 MODELS = [MODEL_NOREX, MODEL_M61] 6447 # Fit, instead of read. Off for On-resonance. 6448 r1_fit = False 6449 # Set the initial guess from the minimum R2eff point 6450 set_grid_r20=True 6451 6452 # Execute the auto-analysis (fast). 6453 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6454 OPT_FUNC_TOL = 1e-1 6455 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6456 OPT_MAX_ITERATIONS = 1000 6457 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6458 6459 # Go 6460 relax_disp.Relax_disp(pipe_name="relax_disp", pipe_bundle="relax_disp", results_dir=outdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6461 6462 # Now simulate that all spins are first deselected, and then selected. 6463 self.interpreter.deselect.all() 6464 sel_ids = [ 6465 ":12", 6466 ":51", 6467 ] 6468 for sel_spin in sel_ids: 6469 print("Selecting spin %s"%sel_spin) 6470 self.interpreter.select.spin(spin_id=sel_spin, change_all=False) 6471 6472 # Inspect which residues should be analysed together for a clustered/global fit. 6473 cluster_ids = sel_ids 6474 6475 # Cluster spins 6476 for curspin in cluster_ids: 6477 print("Adding spin %s to cluster"%curspin) 6478 self.interpreter.relax_disp.cluster('model_cluster', curspin) 6479 6480 # Show the pipe 6481 print("\nPrinting all the available pipes.") 6482 self.interpreter.pipe.display() 6483 6484 # Get the selected models 6485 print("\nChecking which model is stored per spin.") 6486 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6487 print("For spin_id '%s the model is '%s''"%(spin_id, curspin.model)) 6488 6489 # Copy pipe and switch to it. 6490 self.interpreter.pipe.copy(pipe_from="final - relax_disp", pipe_to="relax_disp_cluster", bundle_to="relax_disp_cluster") 6491 self.interpreter.pipe.switch(pipe_name="relax_disp_cluster") 6492 self.interpreter.pipe.display() 6493 6494 # Go again with clustered spins. 6495 relax_disp.Relax_disp(pipe_name="relax_disp_cluster", pipe_bundle="relax_disp_cluster", results_dir=outdir+sep+"cluster", models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6496 6497 # Get the clustered fitted values 6498 print("\nChecking which value is stored per spin.") 6499 kex = None 6500 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6501 if kex == None: 6502 kex = curspin.kex 6503 self.assertEqual(curspin.kex, kex) 6504 print("For spin_id %s the kex is %.3f"%(spin_id, kex))
6505 6506
6507 - def test_repeat_cpmg(self):
6508 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6509 6510 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6511 """ 6512 6513 # Reset. 6514 self.interpreter.reset() 6515 6516 # Define base path to files. 6517 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6518 6519 # Setup dictionary with settings. 6520 sdic = {} 6521 6522 # Spectrometer frqs in list. 6523 sfrq_1 = 499.86214 6524 sfrq_2 = 599.8908587 6525 sfrqs = [sfrq_1, sfrq_2] 6526 6527 # Store in dictionary. 6528 sdic['sfrqs'] = sfrqs 6529 6530 # Store unit for frq. 6531 sdic['sfrq_unit'] = 'MHz' 6532 6533 # Store exp_type 6534 sdic['exp_type'] = 'SQ CPMG' 6535 6536 # Store spin isotope 6537 sdic['isotope'] = '15N' 6538 6539 # How intensity was measured. 6540 sdic['int_method'] = 'height' 6541 6542 # Define the time for result directory. 6543 sdic['time'] = '2014_09' 6544 6545 # Initialize frq dics. 6546 for frq in sfrqs: 6547 key = DIC_KEY_FORMAT % (frq) 6548 sdic[key] = {} 6549 6550 # Set keys. 6551 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6552 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6553 6554 # Store time T2. 6555 sdic[e_1]['time_T2'] = 0.04 6556 sdic[e_2]['time_T2'] = 0.06 6557 6558 # Set ncyc. 6559 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6560 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6561 6562 # Calculate the cpmg_frq and store. 6563 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6564 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6565 6566 # Define peak lists. 6567 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6568 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6569 sdic[e_1]['peaks_folder'] = peaks_folder_1 6570 sdic[e_2]['peaks_folder'] = peaks_folder_2 6571 6572 # Define folder to all rmsd files. 6573 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6574 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6575 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6576 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6577 6578 # Define temporary folder. 6579 sdic['results_dir'] = self.tmpdir 6580 6581 # Setup class with data. 6582 RDR = Relax_disp_rep(sdic) 6583 6584 # Setup base information. 6585 RDR.set_base_cpmg(method='FT', glob_ini=128) 6586 6587 methods = ['FT', 'MDD'] 6588 #methods = ['FT'] 6589 6590 # Set the intensity. 6591 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6592 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6593 6594 # Try plot some intensity correlations. 6595 if True: 6596 selection = None 6597 6598 # Now make a spin selection. 6599 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6600 6601 # For mdd 6602 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6603 6604 # Plot correlation of intensity 6605 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6606 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6607 corr_data = [fig1, fig2] 6608 6609 write_stats = True 6610 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6611 6612 # Open stat file. 6613 if write_stats: 6614 for i, corr_data_i in enumerate(corr_data): 6615 data, methods, glob_inis = corr_data[i] 6616 data_x, data_y = data 6617 method_x, method_y = methods 6618 glob_ini_x, glob_ini_y = glob_inis 6619 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6620 np = len(x) 6621 6622 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6623 6624 if selection == None: 6625 file_name = file_name_ini + '_all.txt' 6626 else: 6627 file_name = file_name_ini + '_sel.txt' 6628 path = RDR.results_dir 6629 data = extract_data(file=file_name, dir=path) 6630 6631 # Loop over the lines. 6632 for i, data_i in enumerate(data): 6633 print(i, data_i) 6634 6635 6636 # Try plot some intensity statistics. 6637 if True: 6638 # Collect r2eff values. 6639 selections = [None, ':2,3'] 6640 for selection in selections: 6641 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6642 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6643 6644 # Get R2eff stats. 6645 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6646 6647 ## Plot R2eff stats 6648 write_stats = True 6649 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6650 6651 # Open stat file. 6652 if write_stats: 6653 if selection == None: 6654 file_name = 'int_stat_all.txt' 6655 else: 6656 file_name = 'int_stat_sel.txt' 6657 path = RDR.results_dir 6658 data = extract_data(file=file_name, dir=path) 6659 6660 # Loop over the lines. 6661 for i, data_i in enumerate(data): 6662 print(i, data_i) 6663 6664 6665 # Try write some R2eff correlations. 6666 if True: 6667 selection = None 6668 # Collect r2eff values. 6669 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6670 6671 # For all spins, mdd 6672 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6673 6674 # Plot correlation of intensity 6675 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6676 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6677 corr_data = [fig1, fig2] 6678 6679 write_stats = True 6680 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6681 6682 # Open stat file. 6683 if write_stats: 6684 for i, corr_data_i in enumerate(corr_data): 6685 data, methods, glob_inis = corr_data[i] 6686 data_x, data_y = data 6687 method_x, method_y = methods 6688 glob_ini_x, glob_ini_y = glob_inis 6689 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6690 np = len(x) 6691 6692 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6693 6694 if selection == None: 6695 file_name = file_name_ini + '_all.txt' 6696 else: 6697 file_name = file_name_ini + '_sel.txt' 6698 path = RDR.results_dir 6699 data = extract_data(file=file_name, dir=path) 6700 6701 # Loop over the lines. 6702 for i, data_i in enumerate(data): 6703 print(i, data_i) 6704 6705 6706 # Try plot some R2eff statistics. 6707 if True: 6708 # Collect r2eff values. 6709 selections = [None, ':2,3'] 6710 for selection in selections: 6711 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6712 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6713 6714 # Get R2eff stats. 6715 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6716 6717 ## Plot R2eff stats 6718 write_stats = True 6719 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6720 6721 # Open stat file. 6722 if write_stats: 6723 if selection == None: 6724 file_name = 'r2eff_stat_all.txt' 6725 else: 6726 file_name = 'r2eff_stat_sel.txt' 6727 path = RDR.results_dir 6728 data = extract_data(file=file_name, dir=path) 6729 6730 # Loop over the lines. 6731 for i, data_i in enumerate(data): 6732 print(i, data_i) 6733 6734 6735 # Do minimisation individual. 6736 if True: 6737 methods = ['FT', 'MDD'] 6738 # Now calculate R2eff. 6739 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6740 6741 min_methods = [['FT'], ['MDD']] 6742 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6743 6744 #min_methods = [['FT']] 6745 #min_list_glob_ini = [[128]] 6746 #selection = ':2,3' 6747 selection = None 6748 6749 for i, methods in enumerate(min_methods): 6750 list_glob_ini = min_list_glob_ini[i] 6751 6752 if True: 6753 # First get data. 6754 if True: 6755 # First load all data. 6756 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6757 6758 # Then set R20 6759 if True: 6760 # Set R20 from min R2eff in preparation for Grid search. 6761 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6762 6763 # Check and print parameters. 6764 if True: 6765 # Print for pipe name 6766 method = methods[0] 6767 glob_ini = list_glob_ini[0] 6768 6769 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6770 RDR.spin_display_params(pipe_name=test_pipe_name) 6771 6772 # Then Grid search. 6773 if True: 6774 # Do Grid search. 6775 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6776 6777 # Then Minimise. 6778 if True: 6779 # Minimise 6780 RDR.opt_max_iterations = int(1e2) 6781 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6782 6783 #print asd 6784 6785 # Plot statistics. 6786 # Try plot some minimisation correlations. 6787 if True: 6788 selections = [None, ':2,3'] 6789 for selection in selections: 6790 # Collect param values. 6791 analysis = 'min_ind' 6792 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6793 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6794 6795 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6796 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6797 corr_data = [fig1, fig2] 6798 6799 write_stats = True 6800 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6801 6802 # Open stat file. 6803 if write_stats: 6804 for i, corr_data_i in enumerate(corr_data): 6805 data, methods, glob_inis = corr_data[i] 6806 data_x, data_y = data 6807 method_x, method_y = methods 6808 glob_ini_x, glob_ini_y = glob_inis 6809 6810 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6811 6812 if selection == None: 6813 file_name = file_name_ini + '_all.txt' 6814 else: 6815 file_name = file_name_ini + '_sel.txt' 6816 path = RDR.results_dir 6817 data = extract_data(file=file_name, dir=path) 6818 6819 # Loop over the lines. 6820 for i, data_i in enumerate(data): 6821 print(i, data_i) 6822 6823 # Try plot some minimisation statistics. 6824 if True: 6825 # Collect param values. 6826 #selections = [None, ':2,3'] 6827 selections = [None, ':2,3'] 6828 for selection in selections: 6829 analysis = 'min_ind' 6830 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6831 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6832 6833 # Get param stats. 6834 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6835 6836 ## Plot R2eff stats 6837 write_stats = True 6838 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6839 6840 # Open stat file. 6841 if write_stats: 6842 if selection == None: 6843 file_name = '%s_stat_all.txt' % (analysis) 6844 else: 6845 file_name = '%s_stat_sel.txt' % (analysis) 6846 path = RDR.results_dir 6847 data = extract_data(file=file_name, dir=path) 6848 6849 # Loop over the lines. 6850 for i, data_i in enumerate(data): 6851 print(i, data_i) 6852 6853 6854 # Do minimisation clustered. 6855 if True: 6856 methods = ['FT', 'MDD'] 6857 # Now calculate R2eff. 6858 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6859 6860 min_methods = [['FT'], ['MDD']] 6861 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6862 6863 #min_methods = [['FT']] 6864 #min_list_glob_ini = [[128]] 6865 selection = ':2,3' 6866 6867 for i, methods in enumerate(min_methods): 6868 list_glob_ini = min_list_glob_ini[i] 6869 6870 if True: 6871 # First get data. 6872 if True: 6873 # First load all data. 6874 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6875 6876 # Then select spins. 6877 if True: 6878 # Deselect all spins. 6879 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6880 6881 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6882 6883 # Then preset values. 6884 if True: 6885 # Set k_AB for Grid search. 6886 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6887 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6888 6889 # Then set R20 6890 if True: 6891 # Set R20 from min R2eff in preparation for Grid search. 6892 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6893 6894 # Check and print parameters. 6895 if True: 6896 # Print for pipe name 6897 method = methods[0] 6898 glob_ini = list_glob_ini[0] 6899 6900 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6901 RDR.spin_display_params(pipe_name=test_pipe_name) 6902 6903 # Then Grid search. 6904 if True: 6905 # Do Grid search. 6906 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6907 6908 # Then cluster spins. 6909 if True: 6910 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6911 6912 # Then Minimise. 6913 if True: 6914 # Minimise 6915 RDR.opt_max_iterations = int(1e2) 6916 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6917 6918 # Plot statistics. 6919 # Try plot some minimisation correlations. 6920 if True: 6921 selection = ':2,3' 6922 # Collect param values. 6923 analysis = 'min' 6924 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6925 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6926 6927 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6928 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6929 corr_data = [fig1, fig2] 6930 6931 write_stats = True 6932 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6933 6934 # Open stat file. 6935 if write_stats: 6936 for i, corr_data_i in enumerate(corr_data): 6937 data, methods, glob_inis = corr_data[i] 6938 data_x, data_y = data 6939 method_x, method_y = methods 6940 glob_ini_x, glob_ini_y = glob_inis 6941 6942 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6943 6944 if selection == None: 6945 file_name = file_name_ini + '_all.txt' 6946 else: 6947 file_name = file_name_ini + '_sel.txt' 6948 path = RDR.results_dir 6949 data = extract_data(file=file_name, dir=path) 6950 6951 # Loop over the lines. 6952 for i, data_i in enumerate(data): 6953 print(i, data_i) 6954 6955 # Try plot some minimisation statistics. 6956 if True: 6957 # Collect param values. 6958 selections = [':2,3'] 6959 for selection in selections: 6960 analysis = 'min' 6961 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6962 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6963 6964 # Get param stats. 6965 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6966 6967 ## Plot R2eff stats 6968 write_stats = True 6969 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6970 6971 # Open stat file. 6972 if write_stats: 6973 if selection == None: 6974 file_name = '%s_stat_all.txt' % (analysis) 6975 else: 6976 file_name = '%s_stat_sel.txt' % (analysis) 6977 path = RDR.results_dir 6978 data = extract_data(file=file_name, dir=path) 6979 6980 # Loop over the lines. 6981 for i, data_i in enumerate(data): 6982 print(i, data_i)
6983 6984
6985 - def test_r1rho_kjaergaard_auto(self):
6986 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6987 6988 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6989 6990 This uses the automatic analysis. 6991 6992 """ 6993 6994 # Cluster residues 6995 cluster_ids = [ 6996 ":13@N", 6997 ":15@N", 6998 ":16@N", 6999 ":25@N", 7000 ":26@N", 7001 ":28@N", 7002 ":39@N", 7003 ":40@N", 7004 ":41@N", 7005 ":43@N", 7006 ":44@N", 7007 ":45@N", 7008 ":49@N", 7009 ":52@N", 7010 ":53@N"] 7011 7012 # Load the data. 7013 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7014 7015 # Test some of the sequence. 7016 self.assertEqual(len(cdp.mol), 1) 7017 self.assertEqual(cdp.mol[0].name, None) 7018 self.assertEqual(len(cdp.mol[0].res), 48) 7019 7020 # Test the chemical shift data. 7021 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 7022 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 7023 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 7024 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 7025 7026 i = 0 7027 for spin, spin_id in spin_loop(return_id=True): 7028 # Check the chemical shift. 7029 self.assertEqual(spin.chemical_shift, cs[i]) 7030 7031 # Increment the index. 7032 i += 1 7033 7034 # Initialize counter 7035 i = 0 7036 j = 0 7037 # Count instances of select/deselect 7038 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 7039 if curspin.select == True: 7040 i += 1 7041 if curspin.select == False: 7042 j += 1 7043 7044 # Test number of selected/deselected spins. 7045 self.assertEqual(i, len(cluster_ids)) 7046 self.assertEqual(j, 48-len(cluster_ids)) 7047 7048 # Check the initial setup. 7049 self.assertEqual(cdp.mol[0].res[7].num, 13) 7050 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 7051 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 7052 7053 self.assertEqual(cdp.mol[0].res[9].num, 15) 7054 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 7055 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 7056 7057 self.assertEqual(cdp.mol[0].res[10].num, 16) 7058 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 7059 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 7060 7061 self.assertEqual(cdp.mol[0].res[16].num, 25) 7062 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 7063 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 7064 7065 self.assertEqual(cdp.mol[0].res[17].num, 26) 7066 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 7067 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 7068 7069 self.assertEqual(cdp.mol[0].res[19].num, 28) 7070 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 7071 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 7072 7073 self.assertEqual(cdp.mol[0].res[29].num, 39) 7074 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 7075 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 7076 7077 self.assertEqual(cdp.mol[0].res[30].num, 40) 7078 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 7079 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 7080 7081 self.assertEqual(cdp.mol[0].res[31].num, 41) 7082 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 7083 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 7084 7085 self.assertEqual(cdp.mol[0].res[33].num, 43) 7086 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 7087 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 7088 7089 self.assertEqual(cdp.mol[0].res[34].num, 44) 7090 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 7091 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 7092 7093 self.assertEqual(cdp.mol[0].res[35].num, 45) 7094 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 7095 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 7096 7097 self.assertEqual(cdp.mol[0].res[38].num, 49) 7098 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 7099 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 7100 7101 self.assertEqual(cdp.mol[0].res[41].num, 52) 7102 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 7103 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 7104 7105 self.assertEqual(cdp.mol[0].res[42].num, 53) 7106 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 7107 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 7108 7109 # The dispersion models. 7110 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7111 7112 # The grid search size (the number of increments per dimension). 7113 GRID_INC = 4 7114 7115 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7116 MC_NUM = 3 7117 7118 # Model selection technique. 7119 MODSEL = 'AIC' 7120 7121 # Execute the auto-analysis (fast). 7122 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7123 OPT_FUNC_TOL = 1e-1 7124 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7125 OPT_MAX_ITERATIONS = 1000 7126 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7127 7128 result_dir_name = ds.tmpdir 7129 7130 # Make all spins free 7131 for curspin in cluster_ids: 7132 self.interpreter.relax_disp.cluster('free spins', curspin) 7133 # Shut them down 7134 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7135 7136 # Select only a subset of spins for global fitting 7137 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7138 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7139 7140 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7141 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7142 7143 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7144 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7145 7146 # Run the analysis. 7147 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7148 7149 # Check the kex value of residue 52 7150 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 7151 7152 # Print results for each model. 7153 print("\n\n################") 7154 print("Printing results") 7155 print("################\n") 7156 for model in MODELS: 7157 # Skip R2eff model. 7158 if model == MODEL_R2EFF: 7159 continue 7160 7161 # Switch to pipe. 7162 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 7163 print("\nModel: %s" % (model)) 7164 7165 # Loop over the spins. 7166 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7167 # Generate spin string. 7168 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 7169 7170 # Loop over the parameters. 7171 print("Optimised parameters for spin: %s" % (spin_string)) 7172 for param in cur_spin.params + ['chi2']: 7173 # Get the value. 7174 if param in ['r1', 'r2']: 7175 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 7176 # Generate the R20 key. 7177 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 7178 7179 # Get the value. 7180 value = getattr(cur_spin, param)[r20_key] 7181 7182 # Print value. 7183 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7184 7185 # For all other parameters. 7186 else: 7187 # Get the value. 7188 value = getattr(cur_spin, param) 7189 7190 # Print value. 7191 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7192 7193 # Print the final pipe. 7194 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 7195 print("\nFinal pipe")
7196 7197
7199 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 7200 7201 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7202 7203 This uses the automatic analysis. 7204 7205 """ 7206 7207 # Cluster residues 7208 cluster_ids = [ 7209 ":52@N"] 7210 7211 # Load the data. 7212 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7213 7214 # The dispersion models. 7215 MODELS = [MODEL_R2EFF] 7216 7217 # The grid search size (the number of increments per dimension). 7218 GRID_INC = 4 7219 7220 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7221 MC_NUM = 3 7222 7223 # Model selection technique. 7224 MODSEL = 'AIC' 7225 7226 # Execute the auto-analysis (fast). 7227 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7228 OPT_FUNC_TOL = 1e-1 7229 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7230 OPT_MAX_ITERATIONS = 1000 7231 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7232 7233 result_dir_name = ds.tmpdir 7234 7235 # Make all spins free 7236 for curspin in cluster_ids: 7237 self.interpreter.relax_disp.cluster('free spins', curspin) 7238 # Shut them down 7239 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7240 7241 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7242 7243 # Run the analysis. 7244 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7245 7246 # Check the graphs produced. 7247 graph_comb = [ 7248 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7249 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7250 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7251 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7252 ] 7253 7254 # Define expected folder names. 7255 result_folders = MODELS 7256 7257 # Assign spin_id. 7258 spin_id = ':52@N' 7259 7260 # Loop over result folders. 7261 for result_folder in result_folders: 7262 # Skip the model R2eff, which does not produce graphs. 7263 if result_folder == MODEL_R2EFF: 7264 continue 7265 7266 # Loop over graphs. 7267 for y_axis, x_axis, interpolate in graph_comb: 7268 # Determine file name: 7269 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7270 7271 # Make the file name. 7272 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7273 7274 # Get the file path. 7275 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7276 7277 print("Testing file access to graph: %s"%file_path) 7278 self.assert_(access(file_path, F_OK)) 7279 7280 # Start testing all possible combinations of graphs. 7281 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7282 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7283 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7284 7285 result_dir_name = ds.tmpdir 7286 7287 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7288 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7289 7290 for result_folder in result_folders: 7291 # Skip the model R2eff, which does not produce graphs. 7292 if result_folder == MODEL_R2EFF: 7293 continue 7294 7295 for y_axis in y_axis_types: 7296 for x_axis in x_axis_types: 7297 for interpolate in interpolate_types: 7298 # Determine file name: 7299 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7300 7301 # Make the file name. 7302 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7303 7304 # Write the curves. 7305 dir = result_dir_name+sep+result_folder 7306 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7307 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7308 7309 # Get the file path. 7310 file_path = get_file_path(file_name, dir) 7311 7312 # Test the plot file exists. 7313 print("Testing file access to graph: %s"%file_path) 7314 self.assert_(access(file_path, F_OK)) 7315 7316 # Now open, and compare content, line by line. 7317 file_prod = open(file_path) 7318 lines_prod = file_prod.readlines() 7319 file_prod.close() 7320 7321 # Define file to compare against. 7322 dir_comp = data_path+sep+result_folder 7323 file_path_comp = get_file_path(file_name, dir_comp) 7324 file_comp = open(file_path_comp) 7325 lines_comp = file_comp.readlines() 7326 file_comp.close() 7327 7328 # Assert number of lines is equal. 7329 self.assertEqual(len(lines_prod), len(lines_comp)) 7330 for j in range(len(lines_prod)): 7331 # Make the string test 7332 first_char = lines_prod[j][0] 7333 if first_char in ["@", "&"]: 7334 self.assertEqual(lines_prod[j], lines_comp[j]) 7335 else: 7336 # Split string in x, y, error. 7337 # The error would change per run. 7338 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7339 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7340 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7341 self.assertAlmostEqual(float(y_prod), float(y_comp))
7342 7343
7345 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7346 7347 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7348 7349 This uses the automatic analysis, with missing loading R1. 7350 7351 """ 7352 7353 # Cluster residues 7354 cluster_ids = [ 7355 ":13@N", 7356 ":15@N", 7357 ":16@N", 7358 ":25@N", 7359 ":26@N", 7360 ":28@N", 7361 ":39@N", 7362 ":40@N", 7363 ":41@N", 7364 ":43@N", 7365 ":44@N", 7366 ":45@N", 7367 ":49@N", 7368 ":52@N", 7369 ":53@N"] 7370 7371 # Load the data. 7372 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7373 7374 # The dispersion models. 7375 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7376 7377 # The grid search size (the number of increments per dimension). 7378 GRID_INC = None 7379 7380 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7381 MC_NUM = 3 7382 7383 # Model selection technique. 7384 MODSEL = 'AIC' 7385 7386 # Execute the auto-analysis (fast). 7387 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7388 OPT_FUNC_TOL = 1e-25 7389 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7390 OPT_MAX_ITERATIONS = 10000000 7391 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7392 7393 result_dir_name = ds.tmpdir 7394 7395 # Make all spins free 7396 for curspin in cluster_ids: 7397 self.interpreter.relax_disp.cluster('free spins', curspin) 7398 # Shut them down 7399 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7400 7401 # Select only a subset of spins for global fitting 7402 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7403 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7404 7405 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7406 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7407 7408 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7409 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7410 7411 # Point to directory with R2eff values, with 2000 MC simulations. 7412 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7413 7414 r1_fit = True 7415 7416 # Run the analysis. 7417 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7418 7419 # Verify the data. 7420 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7421 7422
7423 - def test_r2eff_read(self):
7424 """Test the operation of the relax_disp.r2eff_read user function.""" 7425 7426 # The path to the data files. 7427 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7428 7429 # Read the sequence data. 7430 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7431 7432 # The ID. 7433 id = 'test' 7434 7435 # Set up the metadata. 7436 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7437 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7438 7439 # Try reading the file. 7440 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7441 7442 # Check the global data. 7443 data = [ 7444 ['cpmg_frqs', {'test': 66.667}], 7445 ['cpmg_frqs_list', [66.667]], 7446 ['dispersion_points', 1], 7447 ['exp_type', {'test': 'SQ CPMG'}], 7448 ['exp_type_list', ['SQ CPMG']], 7449 ['spectrometer_frq', {'test': 800000000.0}], 7450 ['spectrometer_frq_count', 1], 7451 ['spectrometer_frq_list', [800000000.0]], 7452 ['spectrum_ids', ['test']] 7453 ] 7454 for name, value in data: 7455 # Does it exist? 7456 self.assert_(hasattr(cdp, name)) 7457 7458 # Check the object. 7459 obj = getattr(cdp, name) 7460 self.assertEqual(obj, value) 7461 7462 # Check the spin data. 7463 data = [ 7464 [1, 2.3035747e+04, 8.5467725e+01], 7465 [2, 9.9629762e+04, 2.8322033e+02], 7466 [3, 9.5663137e+04, 2.8632929e+02], 7467 [4, 1.7089893e+05, 3.1089428e+02], 7468 [5, 4.7323876e+04, 1.0084269e+02], 7469 [6, 2.0199122e+04, 1.0135220e+02], 7470 [7, 1.6655488e+05, 3.1609061e+02], 7471 [8, 9.0061074e+04, 1.9176585e+02], 7472 [10, 8.4726204e+04, 2.8898155e+02], 7473 [11, 1.5050233e+05, 4.3138029e+02], 7474 [12, 9.2998531e+04, 3.0440191e+02], 7475 [13, 1.6343507e+05, 3.3144097e+02], 7476 [14, 1.0137301e+05, 3.7314642e+02], 7477 [15, 8.3407837e+04, 1.6546473e+02], 7478 [16, 1.3819126e+05, 3.3388517e+02], 7479 [17, 1.1010490e+05, 3.5639222e+02], 7480 [18, 9.4324035e+04, 3.2343585e+02], 7481 [19, 1.1135179e+05, 3.0706671e+02], 7482 [20, 7.6339410e+04, 1.7377460e+02], 7483 [21, 6.2008453e+04, 1.7327150e+02], 7484 [22, 1.0590404e+05, 2.4814635e+02], 7485 [23, 1.0630198e+05, 2.3601100e+02], 7486 [24, 7.2996320e+04, 1.4952465e+02], 7487 [25, 9.5486742e+04, 2.7080766e+02], 7488 [26, 5.8067989e+04, 1.6820462e+02], 7489 [27, -1.7168510e+04, 2.2519560e+02], 7490 [28, 1.6891473e+05, 2.3497525e+02], 7491 [29, 9.4038555e+04, 2.0357593e+02], 7492 [30, 2.1386951e+04, 2.2153532e+02], 7493 [31, 9.3982899e+04, 2.0937056e+02], 7494 [32, 8.6097484e+04, 2.3868467e+02], 7495 [33, 1.0194337e+05, 2.7370704e+02], 7496 [34, 8.5683111e+04, 2.0838076e+02], 7497 [35, 8.6985768e+04, 2.0889310e+02], 7498 [36, 8.6011237e+04, 1.7498390e+02], 7499 [37, 1.0984097e+05, 2.7622998e+02], 7500 [38, 8.7017879e+04, 2.6547994e+02], 7501 [39, 9.1682649e+04, 5.2777676e+02], 7502 [40, 7.6370440e+04, 1.9873214e+02], 7503 [41, 9.1393531e+04, 2.4483824e+02], 7504 [42, 1.1017111e+05, 2.8020699e+02], 7505 [43, 9.4552366e+04, 3.4394150e+02], 7506 [44, 1.2858281e+05, 6.8449252e+02], 7507 [45, 7.4583525e+04, 1.9544210e+02], 7508 [46, 9.2087490e+04, 2.0491066e+02], 7509 [47, 9.7507255e+04, 2.5162839e+02], 7510 [48, 1.0033842e+05, 2.7566430e+02], 7511 [49, 1.3048305e+05, 2.6797466e+02], 7512 [50, 1.0546796e+05, 1.9304384e+02], 7513 [51, 9.3099697e+04, 2.0773311e+02], 7514 [52, 4.6863758e+04, 1.3169068e+02], 7515 [53, 6.1055806e+04, 1.5448477e+02], 7516 [55, 6.8629994e+04, 1.6868673e+02], 7517 [56, 1.1005552e+05, 2.1940465e+02], 7518 [57, 1.0572760e+05, 1.9768486e+02], 7519 [58, 1.1176950e+05, 3.0009610e+02], 7520 [59, 9.8758603e+04, 3.3803895e+02], 7521 [60, 9.9517201e+04, 3.5137994e+02], 7522 [61, 5.4357946e+04, 2.5896579e+02], 7523 [62, 1.0899978e+05, 2.8720371e+02], 7524 [63, 8.4549759e+04, 4.1401837e+02], 7525 [64, 5.5014550e+04, 2.1135781e+02], 7526 [65, 8.0569666e+04, 2.3249709e+02], 7527 [66, 1.2936610e+05, 3.5218725e+02], 7528 [67, 3.6438010e+04, 8.7924003e+01], 7529 [70, 3.8763157e+04, 1.3325040e+02], 7530 [71, 8.5711411e+04, 2.9316183e+02], 7531 [72, 3.3211541e+04, 1.2182123e+02], 7532 [73, 3.2070576e+04, 1.2305430e+02] 7533 ] 7534 for res_num, value, error in data: 7535 # Get the spin. 7536 spin = return_spin(spin_id=":%s"%res_num) 7537 7538 # Check the values. 7539 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7540 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7541 7542
7543 - def test_r2eff_read_spin(self):
7544 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7545 7546 # The path to the data files. 7547 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7548 7549 # Generate the sequence. 7550 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7551 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7552 self.interpreter.spin.isotope('1H', spin_id='@H') 7553 self.interpreter.spin.isotope('15N', spin_id='@N') 7554 7555 # Build the experiment IDs. 7556 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7557 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7558 ids = [] 7559 for value in H_disp_points: 7560 ids.append('1H_CPMG_%s' % value) 7561 for value in N_disp_points: 7562 ids.append('15N_CPMG_%s' % value) 7563 print("\n\nThe experiment IDs are %s." % ids) 7564 7565 # Set up the metadata for the experiments. 7566 for id in ids: 7567 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7568 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7569 for value in H_disp_points: 7570 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7571 for value in N_disp_points: 7572 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7573 7574 # Loop over the experiments. 7575 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7576 # Try reading the file. 7577 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7578 7579 # Check the global data. 7580 data = [ 7581 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7582 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7583 ['dispersion_points', 24], 7584 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7585 ['exp_type_list', ['SQ CPMG']], 7586 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7587 ['spectrometer_frq_count', 1], 7588 ['spectrometer_frq_list', [500000000.0]], 7589 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7590 ] 7591 for name, value in data: 7592 # Does it exist? 7593 self.assert_(hasattr(cdp, name)) 7594 7595 # Check the object. 7596 obj = getattr(cdp, name) 7597 if not isinstance(data, dict): 7598 self.assertEqual(obj, value) 7599 7600 # Check the global dictionary data. 7601 else: 7602 for id in ids: 7603 self.assertEqual(obj[id], value[id]) 7604 7605 # Check the spin data. 7606 h_data = [ 7607 [ 67.0, 21.47924, 0.42958], 7608 [ 133.0, 16.73898, 0.33478], 7609 [ 267.0, 9.97357, 0.19947], 7610 [ 400.0, 8.23877, 0.24737], 7611 [ 533.0, 7.59290, 0.24263], 7612 [ 667.0, 7.45843, 0.24165], 7613 [ 800.0, 7.11222, 0.23915], 7614 [ 933.0, 7.40880, 0.24129], 7615 [1067.0, 6.55191, 0.16629], 7616 [1600.0, 6.72177, 0.23637], 7617 [2133.0, 7.09629, 0.23904], 7618 [2667.0, 7.14675, 0.23940] 7619 ] 7620 for disp_point, value, error in h_data: 7621 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7622 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7623 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7624 n_data = [ 7625 [ 50.0, 27.15767, 0.54315], 7626 [ 100.0, 26.55781, 0.53116], 7627 [ 150.0, 24.73462, 0.49469], 7628 [ 200.0, 20.98617, 0.41972], 7629 [ 250.0, 17.82442, 0.35649], 7630 [ 300.0, 15.55352, 0.31107], 7631 [ 350.0, 13.78958, 0.27579], 7632 [ 400.0, 12.48334, 0.24967], 7633 [ 500.0, 11.55724, 0.23114], 7634 [ 600.0, 10.53874, 0.21077], 7635 [ 700.0, 10.07395, 0.20148], 7636 [ 800.0, 9.62952, 0.19259], 7637 [ 900.0, 9.49994, 0.19000], 7638 [1000.0, 8.71350, 0.17427] 7639 ] 7640 for disp_point, value, error in n_data: 7641 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7642 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7643 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7644 7645
7646 - def test_r2eff_fit_fixed_time(self):
7647 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7648 7649 # Execute the script. 7650 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7651 7652
7653 - def test_read_r2eff(self):
7654 """Test the reading of a file containing r2eff values.""" 7655 7656 # Create the sequence data, and name the spins. 7657 self.interpreter.residue.create(1, 'Gly') 7658 self.interpreter.residue.create(2, 'Gly') 7659 self.interpreter.residue.create(3, 'Gly') 7660 7661 # Read the file. 7662 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7663 7664 # Test the data. 7665 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7666 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7667 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7668 7669
7671 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7672 7673 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7674 7675 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7676 'SOD1-WT' CPMG data to the CR72 dispersion model. 7677 7678 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7679 Data is for experiment at 25 degree Celcius. 7680 """ 7681 7682 # Base data setup. 7683 pipe_name = 'base pipe' 7684 pipe_type = 'relax_disp' 7685 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7686 select_spin_index = list(range(0, 1)) 7687 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7688 7689 # Generate r20 key. 7690 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7691 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7692 7693 ## Now prepare for MODEL calculation. 7694 MODEL = "CR72" 7695 7696 # Change pipe. 7697 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7698 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7699 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7700 7701 # Then select model. 7702 self.interpreter.relax_disp.select_model(model=MODEL) 7703 7704 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7705 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7706 7707 # Test result, for normal run. 7708 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7709 # Get the spin_params. 7710 spin_params = spin.params 7711 7712 # Defined fixed values for testing. 7713 if spin_id == ":10@N": 7714 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7715 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7716 7717 # Print out. 7718 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7719 7720 # Testing the r2 values for the different fields are not the same. 7721 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7722 7723 # Test values are larger than 0. 7724 self.assert_(spin.r2[r20_key_600] > 0.0) 7725 self.assert_(spin.r2[r20_key_500] > 0.0) 7726 7727 # Loop over the experiment settings. 7728 r2eff_600 = [] 7729 r2eff_500 = [] 7730 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7731 # Create the data key. 7732 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7733 7734 # Extract the r2 eff data. 7735 r2eff = spin.r2eff[data_key] 7736 if frq == 599.8908617*1E6: 7737 r2eff_600.append(r2eff) 7738 elif frq == 499.862139*1E6: 7739 r2eff_500.append(r2eff) 7740 7741 # Sort values. 7742 r2eff_600.sort() 7743 r2eff_500.sort() 7744 7745 # Test values again. 7746 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7747 print(r2eff_600) 7748 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7749 print("") 7750 7751 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7752 print(r2eff_500) 7753 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7754 print("") 7755 7756 print("###########################################") 7757 print("Trying GRID SEARCH for minimum R2eff values") 7758 7759 ### Test just the Grid search. 7760 GRID_INC = 5 7761 7762 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7763 7764 ### Then test the value.set function. 7765 # Change pipe. 7766 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7767 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7768 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7769 7770 # Then select model. 7771 self.interpreter.relax_disp.select_model(model=MODEL) 7772 7773 # Then set the standard parameter values. 7774 for param in spin_params: 7775 print("Setting standard parameter for param: %s"%param) 7776 self.interpreter.value.set(param=param, index=None) 7777 7778 # Test result, for normal run. 7779 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7780 # Print out. 7781 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7782 7783 # Testing the r2 values. 7784 self.assertEqual(spin.r2[r20_key_600], 10.00) 7785 self.assertEqual(spin.r2[r20_key_500], 10.00) 7786 self.assertEqual(spin.pA, 0.9) 7787 self.assertEqual(spin.dw, 1.0) 7788 self.assertEqual(spin.kex, 1000.0) 7789 7790 print("###########################################") 7791 print("Trying GRID SEARCH for standard R2eff values") 7792 7793 ### Test just the Grid search. 7794 GRID_INC = 5 7795 7796 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7797 7798 ### Run auto_analysis. 7799 # The grid search size (the number of increments per dimension). 7800 GRID_INC = 5 7801 7802 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7803 MC_NUM = 3 7804 7805 # Model selection technique. 7806 MODSEL = 'AIC' 7807 7808 # Execute the auto-analysis (fast). 7809 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7810 OPT_FUNC_TOL = 1e-1 7811 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7812 OPT_MAX_ITERATIONS = 1000 7813 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7814 7815 # Run the analysis. 7816 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7817 7818
7819 - def test_show_apod_extract(self):
7820 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7821 7822 # The path to the data files. 7823 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7824 7825 # Define file name. 7826 file_name = '128_0_FT.ft2' 7827 7828 # Call function. 7829 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7830 7831 # Define how output should look like. 7832 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7833 # Dont test lines which can differ. 7834 show_apod_ver = [ 7835 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7836 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7837 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7838 '', 7839 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7840 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7841 #'', 7842 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7843 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7844 7845 for i, line in enumerate(show_apod_ver): 7846 line_ver = get_output[i] 7847 7848 print(line) 7849 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7850 continue 7851 # Make the string test 7852 self.assertEqual(line, line_ver)
7853 7854
7855 - def test_show_apod_rmsd(self):
7856 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7857 7858 # The path to the data files. 7859 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7860 7861 # Define file name. 7862 file_name = '128_0_FT.ft2' 7863 7864 # Call function. 7865 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7866 7867 # Assert. 7868 self.assertEqual(rmsd, 8583.41)
7869 7870
7872 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7873 7874 # The path to the data files. 7875 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7876 7877 # Call function, and get all file names. 7878 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7879 7880 # Loop over file_paths. 7881 for wfile_path in wfile_paths: 7882 # Open the file. 7883 get_data = extract_data(file=wfile_path) 7884 7885 # Extract line 0, column 0. 7886 test = float(get_data[0][0]) 7887 7888 # Assert. 7889 self.assertEqual(test, 8583.41)
7890 7891
7893 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7894 7895 # The path to the data files. 7896 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7897 7898 # Define file name. 7899 file_name = '128_0_FT.ft2' 7900 7901 # Call function, and get file name. 7902 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7903 7904 # Open the file. 7905 get_data = extract_data(file=wfile_path) 7906 7907 # Extract line 0, column 0. 7908 test = float(get_data[0][0]) 7909 7910 # Assert. 7911 self.assertEqual(test, 8583.41)
7912 7913
7915 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7916 7917 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7918 'SOD1-WT' CPMG data to the CR72 dispersion model. 7919 7920 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7921 Data is for experiment at 25 degree Celcius. 7922 7923 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7924 """ 7925 7926 # Base data setup. 7927 pipe_name = 'base pipe' 7928 pipe_type = 'relax_disp' 7929 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7930 select_spin_index = list(range(0, 1)) 7931 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7932 7933 # Define replicated 7934 repl_A = ['Z_A1', 'Z_A15'] 7935 repl_B = ['Z_B1', 'Z_B18'] 7936 7937 # Loop over spectrum ID, and sort them 7938 spectrum_ids_A = [] 7939 spectrum_ids_B = [] 7940 for spectrum_id in cdp.spectrum_ids: 7941 if "A" in spectrum_id: 7942 spectrum_ids_A.append(spectrum_id) 7943 elif "B" in spectrum_id: 7944 spectrum_ids_B.append(spectrum_id) 7945 7946 # To clean up old error analysis, delete attributes 7947 delattr(cdp, "var_I") 7948 delattr(cdp, "sigma_I") 7949 7950 # Perform error analysis 7951 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7952 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7953 7954 # Loop over spins, save errors to list 7955 Errors_A_B = [] 7956 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7957 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7958 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7959 Errors_A_B.append([A_err, B_err]) 7960 7961 # To clean up old error analysis, delete attributes 7962 delattr(cdp, "var_I") 7963 delattr(cdp, "sigma_I") 7964 7965 # Perform error analysis. Order is important 7966 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7967 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7968 7969 # Loop over spins, save errors to list 7970 Errors_B_A = [] 7971 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7972 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7973 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7974 Errors_B_A.append([A_err, B_err]) 7975 7976 # Make test for order of error 7977 for i in range(len(Errors_A_B)): 7978 Error_A_B = Errors_A_B[i] 7979 Error_B_A = Errors_B_A[i] 7980 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7981 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7982 7983 # Make further tests for fixed values 7984 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7985 std_A_fix = 2785.7263335738567 7986 7987 for id_A in spectrum_ids_A: 7988 self.assertEqual(cdp.sigma_I[id_A], std_A) 7989 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7990 7991 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7992 std_B_fix = 4967.3772030667988 7993 7994 for id_B in spectrum_ids_B: 7995 self.assertEqual(cdp.sigma_I[id_B], std_B) 7996 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7997 7998
7999 - def test_sod1wt_t25_to_cr72(self):
8000 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 8001 8002 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 8003 'SOD1-WT' CPMG data to the CR72 dispersion model. 8004 8005 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 8006 Data is for experiment at 25 degree Celcius. 8007 """ 8008 8009 # Base data setup. 8010 pipe_name = 'base pipe' 8011 pipe_type = 'relax_disp' 8012 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8013 select_spin_index = list(range(0, 2)) 8014 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8015 8016 # Generate r20 key. 8017 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8018 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8019 8020 ## Now prepare for MODEL calculation. 8021 MODEL = "CR72" 8022 8023 # Change pipe. 8024 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 8025 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 8026 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 8027 8028 # Then select model. 8029 self.interpreter.relax_disp.select_model(model=MODEL) 8030 8031 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 8032 GRID_INC = 7 8033 8034 # Store grid and minimisations results. 8035 grid_results = [] 8036 mini_results = [] 8037 clust_results = [] 8038 8039 # Set the R20 parameters in the default grid search using the minimum R2eff value. 8040 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 8041 8042 # Deselect insignificant spins. 8043 self.interpreter.relax_disp.insignificance(level=1.0) 8044 8045 # Perform Grid Search. 8046 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 8047 8048 # Store result. 8049 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8050 # Store grid results. 8051 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8052 8053 ## Now do minimisation. 8054 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8055 set_func_tol = 1e-9 8056 set_max_iter = 100000 8057 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8058 8059 # Store result. 8060 pA_values = [] 8061 kex_values = [] 8062 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8063 # Store minimisation results. 8064 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8065 8066 # Store pA values. 8067 pA_values.append(spin.pA) 8068 8069 # Store kex values. 8070 kex_values.append(spin.kex) 8071 8072 print("\n# Now print before and after minimisation.\n") 8073 8074 # Print results. 8075 for i in range(len(grid_results)): 8076 # Get values. 8077 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8078 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8079 8080 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8081 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8082 8083 ## Prepare for clustering 8084 # Change pipe. 8085 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 8086 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 8087 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 8088 8089 # Then select model. 8090 self.interpreter.relax_disp.select_model(model=MODEL) 8091 8092 # Define cluster id. 8093 cluster_id = 'clust' 8094 8095 # Loop over spins to cluster them. 8096 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8097 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 8098 8099 # Copy over values. 8100 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 8101 8102 # Test the median values is correct 8103 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8104 print(pA_values) 8105 # The the median pA value returned. 8106 self.assertEqual(median(pA_values), spin.pA) 8107 8108 # The the median kex value returned. 8109 self.assertEqual(median(kex_values), spin.kex) 8110 8111 ## Now do minimisation. 8112 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8113 8114 # Store result. 8115 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8116 # Store clust results. 8117 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8118 8119 # Store the outcome of the clustering minimisation. 8120 clust_pA = spin.pA 8121 clust_kex = spin.kex 8122 8123 print("\n# Now testing.\n") 8124 8125 # Define results 8126 test_res = {} 8127 test_res[':10@N'] = {} 8128 test_res[':10@N']['r2600'] = 18.429755324773360 8129 test_res[':10@N']['r2500'] = 16.981349161968630 8130 test_res[':10@N']['dw'] = 2.700755859433969 8131 test_res[':10@N']['pA'] = 0.971531659288657 8132 test_res[':10@N']['kex'] = 3831.766337047963134 8133 test_res[':11@N'] = {} 8134 test_res[':11@N']['r2600'] = 18.193409421115213 8135 test_res[':11@N']['r2500'] = 17.308838135567765 8136 test_res[':11@N']['dw'] = 2.706650302761793 8137 test_res[':11@N']['pA'] = 0.971531659288657 8138 test_res[':11@N']['kex'] = 3831.766337047963134 8139 8140 # Then make tests. 8141 for i in range(len(grid_results)): 8142 # Get values. 8143 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8144 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8145 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 8146 8147 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8148 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8149 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 8150 8151 # Make tests. 8152 self.assertEqual(clust_pA, c_pA) 8153 self.assertEqual(clust_kex, c_kex) 8154 8155 # Test values. 8156 if c_spin_id in test_res: 8157 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 8158 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 8159 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 8160 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 8161 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
8162 8163 # Save disp graph to temp. 8164 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 8165 8166
8168 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 8169 8170 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 8171 'SOD1-WT' CPMG data to the CR72 dispersion model. 8172 8173 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 8174 Data is for experiment at 25 degree Celcius. 8175 """ 8176 8177 # Base data setup. 8178 pipe_name = 'base pipe' 8179 pipe_type = 'relax_disp' 8180 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8181 select_spin_index = list(range(0, 2)) 8182 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8183 8184 # Generate r20 key. 8185 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8186 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8187 8188 # Cluster everything, to analyse together. 8189 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 8190 8191 # Write input 8192 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 8193 8194 # Check the r2eff set files. 8195 print("\nChecking the R2eff input set files.") 8196 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 8197 8198 # First check file exists 8199 for dir, file in files: 8200 print(dir+sep+file) 8201 self.assert_(access(dir+sep+file, F_OK)) 8202 8203 # Define how files should look like 8204 data_set_600 = [ 8205 "60.8272464287\n", 8206 "0.06\n", 8207 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8208 "# G10\n", 8209 " 33.333 26.53556078711 0.5236104771163\n", 8210 " 66.667 25.29735243318 0.48766574122\n", 8211 " 100 25.09470361403 0.4820438864671\n", 8212 " 133.333 25.15603274331 0.4837377286085\n", 8213 " 166.667 24.27213341753 0.4599457904395\n", 8214 " 200 24.00364120328 0.4529773198905\n", 8215 " 266.667 24.03511395168 0.4537880662536\n", 8216 " 300 23.04761040024 0.4291039120557\n", 8217 " 333.333 22.95530300787 0.4268745963972\n", 8218 " 400 23.06158810662 0.4294426293624\n", 8219 " 466.667 22.26799054092 0.4106809618644\n", 8220 " 533.333 21.99851418823 0.4045232104735\n", 8221 " 666.667 21.19651570955 0.3868136173831\n", 8222 " 833.333 20.30938498379 0.3682604887899\n", 8223 " 1000 20.28273252609 0.367719392568\n", 8224 "# D11\n", 8225 " 33.333 24.76520269878 0.5026475808706\n", 8226 " 66.667 24.8773107448 0.5058752916906\n", 8227 " 100 24.90357815239 0.5066348551479\n", 8228 " 133.333 23.7782506151 0.4751950583865\n", 8229 " 166.667 23.68548762076 0.4727017128631\n", 8230 " 200 23.58629651618 0.4700517377679\n", 8231 " 266.667 23.47734671187 0.4671601744044\n", 8232 " 300 24.08647493772 0.4835855560598\n", 8233 " 333.333 22.98314371029 0.4542918950801\n", 8234 " 400 22.80339361568 0.4497107885587\n", 8235 " 466.667 22.91634335366 0.4525833037874\n", 8236 " 533.333 22.59774140046 0.4445334311324\n", 8237 " 666.667 20.9177750759 0.4046955726046\n", 8238 " 833.333 20.71792550566 0.4002363835007\n", 8239 " 1000 19.54080006349 0.3751112751853\n", 8240 ] 8241 8242 # Check data_set_600 8243 file = open(files[0][0]+sep+files[0][1]) 8244 lines = file.readlines() 8245 file.close() 8246 self.assertEqual(len(data_set_600), len(lines)) 8247 for i in range(len(data_set_600)): 8248 # Make the string test 8249 self.assertEqual(data_set_600[i], lines[i]) 8250 8251 # Define how files should look like 8252 data_set_500 = [ 8253 "50.6846152368\n", 8254 "0.04\n", 8255 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8256 "# G10\n", 8257 " 50 22.28084307393 0.2944966344183\n", 8258 " 100 21.93494977761 0.2910362768307\n", 8259 " 150 21.09850032232 0.282892238351\n", 8260 " 200 20.86493960397 0.2806737853646\n", 8261 " 250 20.75287269752 0.2796178205016\n", 8262 " 300 20.25597152406 0.2750013546989\n", 8263 " 350 19.92172163467 0.2719555756504\n", 8264 " 400 19.97712052922 0.272457105051\n", 8265 " 450 19.46807010415 0.2678972122793\n", 8266 " 500 19.76875460947 0.2705774849203\n", 8267 " 550 19.39161367402 0.2672216964327\n", 8268 " 600 19.03949517697 0.2641417899694\n", 8269 " 650 19.12218812132 0.2648605059901\n", 8270 " 700 19.01037461457 0.2638893584683\n", 8271 " 800 18.83395162904 0.2623674321143\n", 8272 " 900 18.47529972436 0.2593123604687\n", 8273 " 1000 18.5252023121 0.2597343394038\n", 8274 "# D11\n", 8275 " 50 22.15403890237 0.3285588379827\n", 8276 " 100 21.80946781746 0.3247185598713\n", 8277 " 150 21.77715415505 0.324361526682\n", 8278 " 200 21.41647464235 0.3204122024881\n", 8279 " 250 21.17099940822 0.3177616325958\n", 8280 " 300 21.03740030577 0.3163316496664\n", 8281 " 350 20.95393648281 0.3154427665172\n", 8282 " 400 20.93311399332 0.315221543436\n", 8283 " 450 20.18219905222 0.3073848655291\n", 8284 " 500 19.93599065085 0.3048744697057\n", 8285 " 550 19.68475725452 0.3023424499113\n", 8286 " 600 19.33575433934 0.2988741928798\n", 8287 " 650 19.53915692194 0.3008886196853\n", 8288 " 700 19.2018754351 0.2975587767134\n", 8289 " 800 18.82360965368 0.2938866923878\n", 8290 " 900 18.71861761238 0.2928790380131\n", 8291 " 1000 17.95878049287 0.2857341721151\n", 8292 ] 8293 8294 # Check data_set_500 8295 file = open(files[1][0]+sep+files[1][1]) 8296 lines = file.readlines() 8297 file.close() 8298 self.assertEqual(len(data_set_500), len(lines)) 8299 for i in range(len(data_set_500)): 8300 # Make the string test 8301 self.assertEqual(data_set_500[i], lines[i]) 8302 8303 # Test local dir tests. This will be turned off in system test. 8304 turn_on_local_dir_test = False 8305 8306 if turn_on_local_dir_test: 8307 ## Now check to local folder with None argument. 8308 # Write input 8309 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8310 8311 # Check the r2eff set files. 8312 print("\nChecking the R2eff input set files.") 8313 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8314 8315 # First check file exists 8316 for dir, file in files: 8317 print(dir+sep+file) 8318 self.assert_(access(dir+sep+file, F_OK)) 8319 8320 ## Now check to local folder with dir argument. 8321 # Write input 8322 set_dir = "Test_ShereKhan" 8323 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8324 8325 # Check the r2eff set files. 8326 print("\nChecking the R2eff input set files.") 8327 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8328 8329 # First check file exists 8330 for dir, file in files: 8331 print(dir+sep+file) 8332 self.assert_(access(dir+sep+file, F_OK))
8333 8334
8335 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8336 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8337 8338 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8339 """ 8340 8341 # Reset. 8342 self.interpreter.reset() 8343 8344 # Create the data pipe and load the base data. 8345 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8346 self.interpreter.state.load(data_path+sep+'r2eff_values') 8347 8348 # The model data pipe. 8349 model = 'MMQ CR72' 8350 pipe_name = "%s - relax_disp" % model 8351 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8352 self.interpreter.pipe.switch(pipe_name=pipe_name) 8353 8354 # Set the model. 8355 self.interpreter.relax_disp.select_model(model=model) 8356 8357 # Cluster everything. 8358 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8359 8360 # Copy the data. 8361 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8362 8363 # Alias the spins. 8364 spin135S = cdp.mol[0].res[0].spin[0] 8365 spin135F = cdp.mol[0].res[0].spin[1] 8366 spin137S = cdp.mol[0].res[1].spin[0] 8367 spin137F = cdp.mol[0].res[1].spin[1] 8368 8369 # The R20 keys. 8370 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8371 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8372 8373 # Set the cluster specific parameters (only for the first spin). 8374 spin135S.pA = 0.836591763632 8375 spin135S.kex = 241.806525261 8376 8377 # Set the initial parameter values. 8378 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8379 spin135S.dw = 0.583003118785 8380 spin135S.dwH = 0.0361441944301 8381 8382 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8383 spin135F.dw = 0.805849745104 8384 spin135F.dwH = 0.0215791945715 8385 8386 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8387 spin137S.dw = 0.688107568372 8388 spin137S.dwH = 0.0344463604043 8389 8390 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8391 spin137F.dw = 0.94978299907 8392 spin137F.dwH = 1.4818877939e-07 8393 8394 # Low precision optimisation. 8395 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8396 8397 # Printout. 8398 print("\n\nOptimised parameters:\n") 8399 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8400 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8401 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8402 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8403 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8404 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8405 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8406 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8407 print("\n # Set the cluster specific parameters (only for the first spin).") 8408 print(" spin135S.pA = %s" % spin135S.pA) 8409 print(" spin135S.kex = %s" % spin135S.kex) 8410 print("\n # Set the initial parameter values.") 8411 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8412 print(" spin135S.dw = %s" % spin135S.dw) 8413 print(" spin135S.dwH = %s" % spin135S.dwH) 8414 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8415 print(" spin135F.dw = %s" % spin135F.dw) 8416 print(" spin135F.dwH = %s" % spin135F.dwH) 8417 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8418 print(" spin137S.dw = %s" % spin137S.dw) 8419 print(" spin137S.dwH = %s" % spin137S.dwH) 8420 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8421 print(" spin137F.dw = %s" % spin137F.dw) 8422 print(" spin137F.dwH = %s" % spin137F.dwH) 8423 8424 # Checks for residue :135S. 8425 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8426 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8427 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8428 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8429 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8430 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8431 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8432 8433 # Checks for residue :135F. 8434 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8435 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8436 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8437 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8438 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8439 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8440 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8441 8442 # Checks for residue :137S. 8443 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8444 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8445 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8446 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8447 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8448 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8449 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8450 8451 # Checks for residue :137F. 8452 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8453 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8454 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8455 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8456 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8457 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8458 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8459 8460
8461 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8462 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8463 8464 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8465 """ 8466 8467 # Reset. 8468 self.interpreter.reset() 8469 8470 # Create the data pipe and load the base data. 8471 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8472 self.interpreter.state.load(data_path+sep+'r2eff_values') 8473 8474 # The model data pipe. 8475 model = 'NS MMQ 2-site' 8476 pipe_name = "%s - relax_disp" % model 8477 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8478 self.interpreter.pipe.switch(pipe_name=pipe_name) 8479 8480 # Set the model. 8481 self.interpreter.relax_disp.select_model(model=model) 8482 8483 # Cluster everything. 8484 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8485 8486 # Copy the data. 8487 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8488 8489 # Alias the spins. 8490 spin135S = cdp.mol[0].res[0].spin[0] 8491 spin135F = cdp.mol[0].res[0].spin[1] 8492 spin137S = cdp.mol[0].res[1].spin[0] 8493 spin137F = cdp.mol[0].res[1].spin[1] 8494 8495 # The R20 keys. 8496 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8497 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8498 8499 # Set the cluster specific parameters (only for the first spin). 8500 spin135S.pA = 0.847378444499757 8501 spin135S.kex = 264.055604934724329 8502 8503 # Set the initial parameter values. 8504 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8505 spin135S.dw = 0.585574008745351 8506 spin135S.dwH = 0.000000000000002 8507 8508 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8509 spin135F.dw = 0.856699277665748 8510 spin135F.dwH = 0.000000000582587 8511 8512 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8513 spin137S.dw = 0.772904450844973 8514 spin137S.dwH = 0.183351478512970 8515 8516 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8517 spin137F.dw = 0.984568590342831 8518 spin137F.dwH = 0.000000001993458 8519 8520 # Low precision optimisation. 8521 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8522 8523 # Printout. 8524 print("\n\nOptimised parameters:\n") 8525 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8526 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8527 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8528 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8529 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8530 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8531 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8532 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8533 8534 # FIXME: Remove this temporary return and properly check the results. 8535 return 8536 8537 # Checks for residue :135S. 8538 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8539 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8540 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8541 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8542 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8543 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8544 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8545 8546 # Checks for residue :135F. 8547 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8548 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8549 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8550 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8551 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8552 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8553 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8554 8555 # Checks for residue :137S. 8556 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8557 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8558 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8559 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8560 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8561 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8562 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8563 8564 # Checks for residue :137F. 8565 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8566 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8567 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8568 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8569 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8570 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8571 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8572 8573
8574 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8575 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8576 8577 # Setup the data. 8578 self.setup_tp02_data_to_ns_r1rho_2site() 8579 8580 # Alias the spins. 8581 spin1 = cdp.mol[0].res[0].spin[0] 8582 spin2 = cdp.mol[0].res[1].spin[0] 8583 8584 # The R20 keys. 8585 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8586 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8587 8588 # Checks for residue :1. 8589 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8590 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8591 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8592 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8593 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8594 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8595 8596 # Checks for residue :2. 8597 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8598 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8599 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8600 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8601 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8602 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8603 8604
8605 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8606 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8607 8608 # Setup the data. 8609 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8610 8611 # Alias the spins. 8612 spin1 = cdp.mol[0].res[0].spin[0] 8613 spin2 = cdp.mol[0].res[1].spin[0] 8614 8615 # The R20 keys. 8616 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8617 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8618 8619 # Checks for residue :1. 8620 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8621 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8622 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8623 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8624 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8625 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8626 8627 # Checks for residue :2. 8628 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8629 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8630 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8631 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8632 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8633 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8634 8635
8636 - def test_tp02_data_to_mp05(self):
8637 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8638 8639 # Fixed time variable and the models. 8640 ds.fixed = True 8641 ds.models = ['R2eff', 'MP05'] 8642 8643 # Execute the script. 8644 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8645 8646 # Switch back to the data pipe for the optimisation. 8647 self.interpreter.pipe.switch('MP05 - relax_disp') 8648 8649 # The equivalent MP05 parameters. 8650 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8651 pA = [0.775055484521586, 0.500000000036595] 8652 kex = [1235.20361276079, 2378.31403454691] 8653 delta_omega = [7.08194146569694, 5.4083562844306] 8654 chi2 = [0.0370400968727768, 0.182141732163934] 8655 8656 # Alias the spins. 8657 spin1 = cdp.mol[0].res[0].spin[0] 8658 spin2 = cdp.mol[0].res[1].spin[0] 8659 8660 # The R20 keys. 8661 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8662 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8663 8664 # Printout. 8665 print("\n\nOptimised parameters:\n") 8666 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8667 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8668 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8669 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8670 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8671 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8672 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8673 8674 # Check each spin. 8675 spin_index = 0 8676 for spin, spin_id in spin_loop(return_id=True): 8677 # Printout. 8678 print("\nSpin %s." % spin_id) 8679 8680 # Check the fitted parameters. 8681 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8682 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8683 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8684 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8685 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8686 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8687 8688 # Increment the spin index. 8689 spin_index += 1
8690 8691
8692 - def test_tp02_data_to_tap03(self):
8693 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8694 8695 # Fixed time variable and the models. 8696 ds.fixed = True 8697 ds.models = ['R2eff', 'TAP03'] 8698 8699 # Execute the script. 8700 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8701 8702 # Switch back to the data pipe for the optimisation. 8703 self.interpreter.pipe.switch('TAP03 - relax_disp') 8704 8705 # The equivalent TAP03 parameters. 8706 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8707 pA = [0.775042569092891, 0.500000000229685] 8708 kex = [1235.20852748765, 2379.47085580169] 8709 delta_omega = [7.08176806468445, 5.40708372863538] 8710 chi2 = [0.0371366837083293, 0.182212857256044] 8711 8712 # Alias the spins. 8713 spin1 = cdp.mol[0].res[0].spin[0] 8714 spin2 = cdp.mol[0].res[1].spin[0] 8715 8716 # The R20 keys. 8717 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8718 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8719 8720 # Printout. 8721 print("\n\nOptimised parameters:\n") 8722 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8723 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8724 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8725 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8726 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8727 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8728 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8729 8730 # Switch to the 'MP05' model data pipe, then check for each spin. 8731 self.interpreter.pipe.switch('TAP03 - relax_disp') 8732 spin_index = 0 8733 for spin, spin_id in spin_loop(return_id=True): 8734 # Printout. 8735 print("\nSpin %s." % spin_id) 8736 8737 # Check the fitted parameters. 8738 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8739 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8740 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8741 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8742 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8743 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8744 8745 # Increment the spin index. 8746 spin_index += 1
8747 8748
8750 """Implementation of Task #7882 U{https://gna.org/task/?7882}: Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals""" 8751 8752 # First check that results are stored with minimisation, to make sure that Sum of Squares are stored (Chi2 without weighting) and degrees of freedom (dof) is stored. 8753 8754 # Load the results file from a clustered minimisation. 8755 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8756 self.interpreter.results.read(file_name) 8757 8758 # Get the spins, which was used for clustering. 8759 spins_cluster = cdp.clustering['sel'] 8760 spins_free = cdp.clustering['free spins'] 8761 8762 # For sanity check, calculate degree of freedom. 8763 cur_spin_id = spins_cluster[0] 8764 cur_spin = return_spin(cur_spin_id) 8765 8766 # Calculate total number of datapoins. 8767 N = len(spins_cluster) 8768 N_dp = N * len(cur_spin.r2eff) 8769 8770 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8771 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8772 dof = N_dp - N_par 8773 8774 # Sanity check of parameters. 8775 print(N_par, N_dp) 8776 8777 # Number of MC 8778 mc_nr = 3 8779 8780 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8781 self.interpreter.monte_carlo.setup(number=mc_nr) 8782 8783 # Create data. 8784 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8785 8786 # Setup MC again. 8787 self.interpreter.monte_carlo.setup(number=mc_nr) 8788 8789 # Create data, and set the fixed error value, without setting the correct distribution. 8790 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8791 8792 # Setup MC again. 8793 self.interpreter.monte_carlo.setup(number=mc_nr) 8794 8795 # Create data, with fixed error distribution, but not setting the error value. 8796 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8797 8798 # Setup MC again. 8799 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8800 8801 # Now select the R2eff model, and try again. Expect raising an error. 8802 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8803 8804 # Setup MC again. 8805 self.interpreter.monte_carlo.setup(number=mc_nr) 8806 8807 # Create data, and assert failure. 8808 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8809 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8810 8811
8812 - def x_test_task_7882_kex_conf(self):
8813 """Test related to Task #7882 U{https://gna.org/task/?7882}: Try making a confidence interval of kex. 8814 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8815 Page 109-111. 8816 """ 8817 8818 # Load the results file from a clustered minimisation. 8819 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8820 self.interpreter.results.read(file_name) 8821 8822 # Get the spins, which was used for clustering. 8823 spins_cluster = cdp.clustering['sel'] 8824 spins_free = cdp.clustering['free spins'] 8825 8826 # For sanity check, calculate degree of freedom. 8827 cur_spin_id = spins_cluster[0] 8828 cur_spin = return_spin(cur_spin_id) 8829 8830 # Calculate total number of datapoins. 8831 Ns = len(spins_cluster) 8832 N_dp = Ns * len(cur_spin.r2eff) 8833 8834 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8835 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8836 dof_fit = N_dp - N_par 8837 8838 # Assert values. 8839 self.assertEqual(Ns, 61) 8840 self.assertEqual(N_dp, 1952) 8841 self.assertEqual(N_par, 185) 8842 8843 # Confidence interval of kex. 8844 # The number of parameters to check is kex = 1. 8845 P = 1 8846 # Number of datapoints 8847 N = N_dp 8848 # The degrees of freedom for this confidence interval 8849 dof_conf = N - P 8850 8851 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8852 # Can be calculated with microsoft excel: 8853 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8854 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8855 F = 3.8462295505435562 8856 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8857 scale = F*P/dof_conf +1 8858 8859 # Get the sum of best fit. 8860 SSbest_fit = cur_spin.chi2 8861 SSbest_kex = cur_spin.kex 8862 8863 # Get the scaled sum of best fit 8864 SSall_fixed = SSbest_fit * scale 8865 8866 print(SSbest_fit, scale, SSall_fixed) 8867 8868 # Now generate a list of kex values to try. 8869 kex_cur = cur_spin.kex 8870 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8871 8872 chi2_list = [] 8873 8874 for kex in kex_list: 8875 self.interpreter.value.set(val=kex, param='kex') 8876 8877 # Calculate the chi2 values. 8878 self.interpreter.minimise.calculate(verbosity=0) 8879 8880 # Get the chi2 value 8881 chi2_cur = cur_spin.chi2 8882 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8883 8884 # Add to list 8885 chi2_list.append(chi2_cur) 8886 8887 # Now make to numpy array. 8888 chi2_list = asarray(chi2_list) 8889 8890 # Now make a selection mask based on the criteria. 8891 sel_mask = chi2_list < SSall_fixed 8892 8893 # Select values of kex, and chi2_list 8894 kex_sel = kex_list[sel_mask] 8895 chi2_sel = chi2_list[sel_mask] 8896 8897 # Now make plot 8898 print(SSbest_kex, SSbest_fit, SSall_fixed) 8899 print(kex_sel) 8900 print(chi2_sel) 8901 8902 if True: 8903 import matplotlib.pyplot as plt 8904 8905 plt.plot(kex_sel, chi2_sel, "bo") 8906 plt.plot(SSbest_kex, SSbest_fit, "g*") 8907 plt.show()
8908 8909
8910 - def test_tp02_data_to_tp02(self):
8911 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8912 8913 # Fixed time variable. 8914 ds.fixed = True 8915 8916 # Execute the script. 8917 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8918 8919 # The original parameters. 8920 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8921 pA = 0.7654321 8922 kex = 1234.56789 8923 delta_omega = [7.0, 9.0] 8924 8925 # The R20 keys. 8926 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8927 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8928 8929 # Switch to the 'TP02' model data pipe, then check for each spin. 8930 self.interpreter.pipe.switch('TP02 - relax_disp') 8931 spin_index = 0 8932 for spin, spin_id in spin_loop(return_id=True): 8933 # Printout. 8934 print("\nSpin %s." % spin_id) 8935 8936 # Check the fitted parameters. 8937 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8938 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8939 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8940 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8941 8942 # Increment the spin index. 8943 spin_index += 1
8944 8945
8947 """System test of the value.write function to write intensities for an R1rho setup. 8948 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8949 8950 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8951 """ 8952 8953 # Load the state. 8954 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8955 self.interpreter.state.load(statefile, force=True) 8956 8957 # Set filepaths. 8958 int_filepath = ds.tmpdir+sep+'int.out' 8959 8960 # Write out the intensity parameter file. 8961 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8962 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8963 8964 # Test the file exists. 8965 self.assert_(access(int_filepath, F_OK)) 8966 8967 # Open the files for testing. 8968 int_file = open(int_filepath, 'r') 8969 8970 # Loop over the intensity file to test values. 8971 for line in int_file: 8972 # Skip lines starting with #. 8973 if line[0] == "#": 8974 continue 8975 8976 # Split the line 8977 linesplit = line.split() 8978 8979 # Assume values 8980 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8981 self.assertEqual(linesplit[5], "115571.4") 8982 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8983 self.assertEqual(linesplit[5], "68377.52") 8984 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8985 self.assertEqual(linesplit[5], "9141.689") 8986 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8987 self.assertEqual(linesplit[5], "29123.77") 8988 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8989 self.assertEqual(linesplit[5], "58914.94") 8990 8991 # Close files 8992 int_file.close()
8993 8994
8996 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8997 8998 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8999 """ 9000 9001 # Load the state. 9002 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 9003 self.interpreter.state.load(statefile, force=True) 9004 9005 # Set filepaths. 9006 theta_filepath = ds.tmpdir+sep+'theta.out' 9007 9008 # Write out the theta parameter file. 9009 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 9010 9011 # Test the file exists. 9012 self.assert_(access(theta_filepath, F_OK)) 9013 9014 # Open the files for testing. 9015 theta_file = open(theta_filepath, 'r') 9016 9017 # Loop over the theta file to test values. 9018 for line in theta_file: 9019 # Skip lines starting with #. 9020 if line[0] == "#": 9021 continue 9022 # Print lines, not including newline character. 9023 print(line[:-1]) 9024 9025 # Split the line 9026 linesplit = line.split() 9027 9028 # Assume values 9029 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9030 self.assertNotEqual(linesplit[5], "None") 9031 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9032 self.assertNotEqual(linesplit[5], "None") 9033 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9034 self.assertNotEqual(linesplit[5], "None") 9035 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9036 self.assertNotEqual(linesplit[5], "None") 9037 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9038 self.assertNotEqual(linesplit[5], "None") 9039 9040 # Close files 9041 theta_file.close()
9042 9043
9045 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 9046 9047 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 9048 """ 9049 9050 # Load the state. 9051 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 9052 self.interpreter.state.load(statefile, force=True) 9053 9054 # Set filepaths. 9055 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 9056 9057 # Write out the w_eff parameter file. 9058 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 9059 9060 # Test the file exists. 9061 self.assert_(access(w_eff_filepath, F_OK)) 9062 9063 # Open the files for testing. 9064 w_eff_file = open(w_eff_filepath, 'r') 9065 9066 # Loop over the w_eff file to test values. 9067 for line in w_eff_file: 9068 # Skip lines starting with #. 9069 if line[0] == "#": 9070 continue 9071 # Print lines, not including newline character. 9072 print(line[:-1]) 9073 9074 # Split the line 9075 linesplit = line.split() 9076 9077 # Assume values 9078 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9079 self.assertNotEqual(linesplit[5], "None") 9080 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9081 self.assertNotEqual(linesplit[5], "None") 9082 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9083 self.assertNotEqual(linesplit[5], "None") 9084 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9085 self.assertNotEqual(linesplit[5], "None") 9086 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9087 self.assertNotEqual(linesplit[5], "None") 9088 9089 # Close files 9090 w_eff_file.close()
9091 9092
9094 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 9095 9096 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 9097 """ 9098 9099 # Load the state. 9100 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 9101 self.interpreter.state.load(statefile, force=True) 9102 9103 # Set pipe name, bundle and type. 9104 pipe_name = 'base pipe' 9105 pipe_bundle = 'relax_disp' 9106 pipe_type = 'relax_disp' 9107 9108 # The path to the data files. 9109 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 9110 9111 # Deselect all spins 9112 self.interpreter.deselect.all() 9113 9114 # Specify spins to be selected. 9115 select_spin_ids = [ 9116 ":13@N", 9117 ":15@N", 9118 ":16@N", 9119 ":25@N", 9120 ":26@N", 9121 ":28@N", 9122 ":39@N", 9123 ":40@N", 9124 ":41@N", 9125 ":43@N", 9126 ":44@N", 9127 ":45@N", 9128 ":49@N", 9129 ":52@N", 9130 ":53@N"] 9131 9132 # Reverse the selection for the spins. 9133 for curspin in select_spin_ids: 9134 print("Selecting spin %s"%curspin) 9135 self.interpreter.deselect.reverse(spin_id=curspin) 9136 9137 # Read the R1 data 9138 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 9139 9140 # The dispersion models. 9141 MODELS = ['R2eff'] 9142 9143 # The grid search size (the number of increments per dimension). 9144 GRID_INC = 4 9145 9146 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 9147 MC_NUM = 3 9148 9149 # Model selection technique. 9150 MODSEL = 'AIC' 9151 9152 # Execute the auto-analysis (fast). 9153 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 9154 OPT_FUNC_TOL = 1e-1 9155 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 9156 OPT_MAX_ITERATIONS = 1000 9157 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 9158 9159 # Run the analysis. 9160 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 9161 9162 ## Check for file creation 9163 # Set filepaths. 9164 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 9165 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 9166 9167 # Test the files exists. 9168 self.assert_(access(theta_filepath, F_OK)) 9169 self.assert_(access(w_eff_filepath, F_OK)) 9170 9171 # Open the files for testing. 9172 theta_file = open(theta_filepath, 'r') 9173 theta_result = [ 9174 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 9175 "#\n", 9176 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9177 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9178 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9179 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9180 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9181 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9182 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9183 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9184 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 9185 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9186 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 9187 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 9188 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9189 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9190 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9191 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9192 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9193 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 9194 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 9195 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9196 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 9197 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9198 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9199 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9200 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9201 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9202 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9203 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9204 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9205 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9206 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 9207 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 9208 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 9209 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9210 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 9211 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 9212 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 9213 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9214 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9215 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 9216 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9217 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9218 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 9219 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 9220 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9221 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9222 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9223 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9224 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9225 ] 9226 # Check the created theta file. 9227 lines = theta_file.readlines() 9228 for i in range(len(lines)): 9229 # Test lines starting with # 9230 if theta_result[i][0] == "#": 9231 self.assertEqual(theta_result[i], lines[i]) 9232 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9233 if theta_result[i] == lines[i]: 9234 self.assertEqual(theta_result[i], lines[i]) 9235 # If the line is not equal each other, make a slower comparison of values. 9236 else: 9237 # Print lines if they don't match. To help find differences. 9238 print(theta_result[i]) 9239 print(lines[i]) 9240 9241 # First test first 62 characters containing spin information 9242 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9243 9244 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9245 theta_result_s = theta_result[i][62:].split()[::2] 9246 print(theta_result_s ) 9247 lines_s = lines[i][62:].split()[::2] 9248 print(lines_s) 9249 # Loop over the value elements 9250 for j in range(len(lines_s)): 9251 print(theta_result_s[j], lines_s[j]) 9252 # Assume a precision to digits. 9253 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9254 9255 # Close file 9256 theta_file.close() 9257 9258 w_eff_file = open(w_eff_filepath, 'r') 9259 w_eff_result = [ 9260 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9261 "#\n", 9262 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9263 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9264 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9265 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9266 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9267 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9268 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9269 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9270 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 9271 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9272 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 9273 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 9274 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9275 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9276 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9277 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9278 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9279 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 9280 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 9281 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9282 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 9283 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9284 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9285 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9286 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9287 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9288 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9289 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9290 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9291 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9292 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 9293 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 9294 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 9295 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9296 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 9297 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 9298 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 9299 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9300 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9301 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 9302 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9303 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9304 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 9305 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 9306 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9307 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9308 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9309 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9310 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9311 ] 9312 # Check the created w_eff file. 9313 lines = w_eff_file.readlines() 9314 for i in range(len(lines)): 9315 # Test lines starting with # 9316 if w_eff_result[i][0] == "#": 9317 self.assertEqual(w_eff_result[i], lines[i]) 9318 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9319 if w_eff_result[i] == lines[i]: 9320 self.assertEqual(w_eff_result[i], lines[i]) 9321 # If the line is not equal each other, make a slower comparison of values. 9322 else: 9323 # Print lines if they don't match. To help find differences. 9324 print(w_eff_result[i]) 9325 print(lines[i]) 9326 9327 # First test first 62 characters containing spin information 9328 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9329 9330 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9331 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9332 print(w_eff_result_s ) 9333 lines_s = lines[i][62:].split()[::2] 9334 print(lines_s) 9335 # Loop over the value elements 9336 for j in range(len(lines_s)): 9337 print(w_eff_result_s[j], lines_s[j]) 9338 # Assume a precision to digits. 9339 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9340 9341 # Close file 9342 w_eff_file.close()
9343 9344
9346 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9347 9348 This follows Task 7822. 9349 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 9350 9351 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9352 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9353 """ 9354 9355 # Load the data. 9356 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9357 9358 # Set pipe name, bundle and type. 9359 pipe_name = 'base pipe' 9360 pipe_bundle = 'relax_disp' 9361 pipe_type = 'relax_disp' 9362 9363 # Create the data pipe. 9364 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9365 9366 file = data_path + '1_setup_r1rho_GUI.py' 9367 self.interpreter.script(file=file, dir=None) 9368 9369 # Deselect all spins. 9370 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9371 9372 # Select one spin. 9373 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9374 9375 # Set the model. 9376 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9377 9378 # Check if intensity errors have already been calculated. 9379 check_intensity_errors() 9380 9381 # Do a grid search. 9382 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9383 9384 # Set algorithm. 9385 min_algor = 'Newton' 9386 constraints = True 9387 if constraints: 9388 min_options = ('%s'%(min_algor),) 9389 #min_algor = 'Log barrier' 9390 min_algor = 'Method of Multipliers' 9391 scaling_matrix = assemble_scaling_matrix(scaling=True) 9392 9393 # Collect spins 9394 all_spin_ids = [] 9395 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9396 all_spin_ids.append(spin_id) 9397 9398 spins = spin_ids_to_containers(all_spin_ids[:1]) 9399 9400 # Get constraints 9401 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9402 else: 9403 min_options = () 9404 A, b = None, None 9405 min_options = () 9406 sim_boot = 200 9407 scaling_list = [1.0, 1.0] 9408 9409 # Minimise. 9410 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9411 9412 # Loop over old err attributes. 9413 err_attr_list = ['r2eff_err', 'i0_err'] 9414 9415 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9416 # Loop over old err attributes. 9417 for err_attr in err_attr_list: 9418 if hasattr(cur_spin, err_attr): 9419 delattr(cur_spin, err_attr) 9420 9421 # Collect the estimation data from boot. 9422 my_dic = {} 9423 param_key_list = [] 9424 est_keys = [] 9425 est_key = '-2' 9426 est_keys.append(est_key) 9427 spin_id_list = [] 9428 9429 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9430 # Add key to dic. 9431 my_dic[spin_id] = {} 9432 9433 # Add key for estimate. 9434 my_dic[spin_id][est_key] = {} 9435 9436 # Add spin key to list. 9437 spin_id_list.append(spin_id) 9438 9439 # Generate spin string. 9440 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9441 9442 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9443 # Generate the param_key. 9444 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9445 9446 # Append key. 9447 param_key_list.append(param_key) 9448 9449 # Add key to dic. 9450 my_dic[spin_id][est_key][param_key] = {} 9451 9452 values = [] 9453 errors = [] 9454 times = [] 9455 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9456 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9457 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9458 times.append(time) 9459 9460 # Convert to numpy array. 9461 values = asarray(values) 9462 errors = asarray(errors) 9463 times = asarray(times) 9464 9465 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9466 i0 = getattr(cur_spin, 'i0')[param_key] 9467 9468 R_m_sim_l = [] 9469 I0_m_sim_l = [] 9470 for j in range(sim_boot): 9471 if j in range(0, 100000, 100): 9472 print("Simulation %i"%j) 9473 # Start minimisation. 9474 9475 # Produce errors 9476 I_err = [] 9477 for j, error in enumerate(errors): 9478 I_error = gauss(values[j], error) 9479 I_err.append(I_error) 9480 # Convert to numpy array. 9481 I_err = asarray(I_err) 9482 9483 x0 = [r2eff, i0] 9484 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9485 9486 # Ref input. 9487 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9488 # l=l, u=u, c=c, dc=dc, d2c=d2c 9489 # l: Lower bound constraint vector (l <= x <= u). 9490 # u: Upper bound constraint vector (l <= x <= u). 9491 # c: User supplied constraint function. 9492 # dc: User supplied constraint gradient function. 9493 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9494 9495 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9496 R_m_sim_l.append(R_m_sim_j) 9497 I0_m_sim_l.append(I0_m_sim_j) 9498 9499 # Get stats on distribution. 9500 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9501 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9502 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9503 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9504 9505 # Estimate R2eff errors. 9506 self.interpreter.relax_disp.r2eff_err_estimate() 9507 9508 est_key = '-1' 9509 est_keys.append(est_key) 9510 9511 # Collect data. 9512 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9513 # Add key for estimate. 9514 my_dic[spin_id][est_key] = {} 9515 9516 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9517 # Generate the param_key. 9518 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9519 9520 # Add key to dic. 9521 my_dic[spin_id][est_key][param_key] = {} 9522 9523 # Get the value. 9524 # Loop over err attributes. 9525 for err_attr in err_attr_list: 9526 if hasattr(cur_spin, err_attr): 9527 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9528 else: 9529 get_err_attr = 0.0 9530 9531 # Save to dic. 9532 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9533 9534 9535 # Make Carlo Simulations number 9536 mc_number_list = list(range(0, 1000, 250)) 9537 9538 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9539 9540 # Loop over the Monte Carlo simulations: 9541 for number in mc_number_list: 9542 # First delete old simulations. 9543 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9544 # Loop over old err attributes. 9545 for err_attr in err_attr_list: 9546 if hasattr(cur_spin, err_attr): 9547 delattr(cur_spin, err_attr) 9548 9549 # Loop over the simulated attributes. 9550 for sim_attr in sim_attr_list: 9551 if hasattr(cur_spin, sim_attr): 9552 delattr(cur_spin, sim_attr) 9553 9554 self.interpreter.monte_carlo.setup(number=number) 9555 self.interpreter.monte_carlo.create_data() 9556 self.interpreter.monte_carlo.initial_values() 9557 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9558 self.interpreter.eliminate() 9559 self.interpreter.monte_carlo.error_analysis() 9560 9561 est_key = '%i'%number 9562 est_keys.append(est_key) 9563 9564 # Collect data. 9565 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9566 # Add key for estimate. 9567 my_dic[spin_id][est_key] = {} 9568 9569 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9570 # Generate the param_key. 9571 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9572 9573 # Add key to dic. 9574 my_dic[spin_id][est_key][param_key] = {} 9575 9576 # Get the value. 9577 # Loop over err attributes. 9578 for err_attr in err_attr_list: 9579 if hasattr(cur_spin, err_attr): 9580 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9581 else: 9582 get_err_attr = 0.0 9583 9584 # Save to dic. 9585 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9586 9587 # Set what to extract. 9588 err_attr = err_attr_list[0] 9589 9590 # Define list with text. 9591 text_list = [] 9592 9593 # Now loop through the data. 9594 for spin_id in spin_id_list: 9595 for est_key in est_keys: 9596 # Define list to pickup data. 9597 r2eff_err_list = [] 9598 9599 for param_key in param_key_list: 9600 # Get the value. 9601 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9602 9603 # Add to list. 9604 r2eff_err_list.append(r2eff_err) 9605 9606 # Sum the list 9607 sum_array = sum(array(r2eff_err_list)) 9608 9609 # Join floats to string. 9610 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9611 9612 # Define print string. 9613 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9614 text_list.append(text) 9615 9616 9617 # Now print. 9618 filepath = NamedTemporaryFile(delete=False).name 9619 # Open the files for testing. 9620 w_file = open(filepath, 'w') 9621 9622 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9623 9624 for text in text_list: 9625 # Print. 9626 print(text) 9627 9628 # Write to file. 9629 w_file.write(text+"\n") 9630 9631 # Close files 9632 w_file.close() 9633 9634 print("Filepath is: %s"%filepath) 9635 print("Start 'gnuplot' and write:") 9636 print("set term dumb") 9637 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9638 9639
9640 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9641 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9642 9643 # Check the kex value of residue 52 9644 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9645 9646 # Print results for each model. 9647 print("\n\n################") 9648 print("Printing results") 9649 print("################\n") 9650 for model in models: 9651 # Skip R2eff model. 9652 if model == MODEL_R2EFF: 9653 continue 9654 9655 # Switch to pipe. 9656 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9657 print("\nModel: %s" % (model)) 9658 9659 # Loop over the spins. 9660 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9661 # Generate spin string. 9662 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9663 9664 # Loop over the parameters. 9665 print("Optimised parameters for spin: %s" % (spin_string)) 9666 for param in cur_spin.params + ['chi2']: 9667 # Get the value. 9668 if param in ['r1', 'r2']: 9669 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9670 # Generate the R20 key. 9671 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9672 9673 # Get the value. 9674 value = getattr(cur_spin, param)[r20_key] 9675 9676 # Print value. 9677 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9678 9679 # Compare values. 9680 if spin_id == ':52@N': 9681 if param == 'r1': 9682 if model == MODEL_NOREX: 9683 if r2eff_estimate == 'direct': 9684 self.assertAlmostEqual(value, 1.46138805) 9685 elif r2eff_estimate == 'MC2000': 9686 self.assertAlmostEqual(value, 1.46328102) 9687 elif r2eff_estimate == 'chi2_pyt': 9688 self.assertAlmostEqual(value, 1.43820629) 9689 elif model == MODEL_DPL94: 9690 if r2eff_estimate == 'direct': 9691 self.assertAlmostEqual(value, 1.44845742) 9692 elif r2eff_estimate == 'MC2000': 9693 self.assertAlmostEqual(value, 1.45019848) 9694 elif r2eff_estimate == 'chi2_pyt': 9695 self.assertAlmostEqual(value, 1.44666512) 9696 elif model == MODEL_TP02: 9697 if r2eff_estimate == 'direct': 9698 self.assertAlmostEqual(value, 1.54354392) 9699 elif r2eff_estimate == 'MC2000': 9700 self.assertAlmostEqual(value, 1.54352369) 9701 elif r2eff_estimate == 'chi2_pyt': 9702 self.assertAlmostEqual(value, 1.55964020) 9703 elif model == MODEL_TAP03: 9704 if r2eff_estimate == 'direct': 9705 self.assertAlmostEqual(value, 1.54356410) 9706 elif r2eff_estimate == 'MC2000': 9707 self.assertAlmostEqual(value, 1.54354367) 9708 elif r2eff_estimate == 'chi2_pyt': 9709 self.assertAlmostEqual(value, 1.55967157) 9710 elif model == MODEL_MP05: 9711 if r2eff_estimate == 'direct': 9712 self.assertAlmostEqual(value, 1.54356416) 9713 elif r2eff_estimate == 'MC2000': 9714 self.assertAlmostEqual(value, 1.54354372) 9715 elif r2eff_estimate == 'chi2_pyt': 9716 self.assertAlmostEqual(value, 1.55967163) 9717 elif model == MODEL_NS_R1RHO_2SITE: 9718 if r2eff_estimate == 'direct': 9719 self.assertAlmostEqual(value, 1.41359221, 5) 9720 elif r2eff_estimate == 'MC2000': 9721 self.assertAlmostEqual(value, 1.41321968, 5) 9722 elif r2eff_estimate == 'chi2_pyt': 9723 self.assertAlmostEqual(value, 1.36303129, 5) 9724 9725 elif param == 'r2': 9726 if model == MODEL_NOREX: 9727 if r2eff_estimate == 'direct': 9728 self.assertAlmostEqual(value, 11.48392439) 9729 elif r2eff_estimate == 'MC2000': 9730 self.assertAlmostEqual(value, 11.48040934) 9731 elif r2eff_estimate == 'chi2_pyt': 9732 self.assertAlmostEqual(value, 11.47224488) 9733 elif model == MODEL_DPL94: 9734 if r2eff_estimate == 'direct': 9735 self.assertAlmostEqual(value, 10.15688372, 6) 9736 elif r2eff_estimate == 'MC2000': 9737 self.assertAlmostEqual(value, 10.16304887, 6) 9738 elif r2eff_estimate == 'chi2_pyt': 9739 self.assertAlmostEqual(value, 9.20037797, 6) 9740 elif model == MODEL_TP02: 9741 if r2eff_estimate == 'direct': 9742 self.assertAlmostEqual(value, 9.72654896, 6) 9743 elif r2eff_estimate == 'MC2000': 9744 self.assertAlmostEqual(value, 9.72772726, 6) 9745 elif r2eff_estimate == 'chi2_pyt': 9746 self.assertAlmostEqual(value, 9.53948340, 6) 9747 elif model == MODEL_TAP03: 9748 if r2eff_estimate == 'direct': 9749 self.assertAlmostEqual(value, 9.72641887, 6) 9750 elif r2eff_estimate == 'MC2000': 9751 self.assertAlmostEqual(value, 9.72759374, 6) 9752 elif r2eff_estimate == 'chi2_pyt': 9753 self.assertAlmostEqual(value, 9.53926913, 6) 9754 elif model == MODEL_MP05: 9755 if r2eff_estimate == 'direct': 9756 self.assertAlmostEqual(value, 9.72641723, 6) 9757 elif r2eff_estimate == 'MC2000': 9758 self.assertAlmostEqual(value, 9.72759220, 6) 9759 elif r2eff_estimate == 'chi2_pyt': 9760 self.assertAlmostEqual(value, 9.53926778, 6) 9761 elif model == MODEL_NS_R1RHO_2SITE: 9762 if r2eff_estimate == 'direct': 9763 self.assertAlmostEqual(value, 9.34531535, 5) 9764 elif r2eff_estimate == 'MC2000': 9765 self.assertAlmostEqual(value, 9.34602793, 5) 9766 elif r2eff_estimate == 'chi2_pyt': 9767 self.assertAlmostEqual(value, 9.17631409, 5) 9768 9769 # For all other parameters. 9770 else: 9771 # Get the value. 9772 value = getattr(cur_spin, param) 9773 9774 # Print value. 9775 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9776 9777 # Compare values. 9778 if spin_id == ':52@N': 9779 if param == 'phi_ex': 9780 if model == MODEL_DPL94: 9781 if r2eff_estimate == 'direct': 9782 self.assertAlmostEqual(value, 0.07599563) 9783 elif r2eff_estimate == 'MC2000': 9784 self.assertAlmostEqual(value, 0.07561937) 9785 elif r2eff_estimate == 'chi2_pyt': 9786 self.assertAlmostEqual(value, 0.12946061) 9787 9788 elif param == 'pA': 9789 if model == MODEL_TP02: 9790 if r2eff_estimate == 'direct': 9791 self.assertAlmostEqual(value, 0.88827040) 9792 elif r2eff_estimate == 'MC2000': 9793 self.assertAlmostEqual(value, 0.88807487) 9794 elif r2eff_estimate == 'chi2_pyt': 9795 self.assertAlmostEqual(value, 0.87746233) 9796 elif model == MODEL_TAP03: 9797 if r2eff_estimate == 'direct': 9798 self.assertAlmostEqual(value, 0.88828922) 9799 elif r2eff_estimate == 'MC2000': 9800 self.assertAlmostEqual(value, 0.88809318) 9801 elif r2eff_estimate == 'chi2_pyt': 9802 self.assertAlmostEqual(value, 0.87747558) 9803 elif model == MODEL_MP05: 9804 if r2eff_estimate == 'direct': 9805 self.assertAlmostEqual(value, 0.88828924, 6) 9806 elif r2eff_estimate == 'MC2000': 9807 self.assertAlmostEqual(value, 0.88809321) 9808 elif r2eff_estimate == 'chi2_pyt': 9809 self.assertAlmostEqual(value, 0.87747562) 9810 elif model == MODEL_NS_R1RHO_2SITE: 9811 if r2eff_estimate == 'direct': 9812 self.assertAlmostEqual(value, 0.94504369, 6) 9813 elif r2eff_estimate == 'MC2000': 9814 self.assertAlmostEqual(value, 0.94496541, 6) 9815 elif r2eff_estimate == 'chi2_pyt': 9816 self.assertAlmostEqual(value, 0.92084707, 6) 9817 9818 elif param == 'dw': 9819 if model == MODEL_TP02: 9820 if r2eff_estimate == 'direct': 9821 self.assertAlmostEqual(value, 1.08875840, 6) 9822 elif r2eff_estimate == 'MC2000': 9823 self.assertAlmostEqual(value, 1.08765638, 6) 9824 elif r2eff_estimate == 'chi2_pyt': 9825 self.assertAlmostEqual(value, 1.09753230, 6) 9826 elif model == MODEL_TAP03: 9827 if r2eff_estimate == 'direct': 9828 self.assertAlmostEqual(value, 1.08837238, 6) 9829 elif r2eff_estimate == 'MC2000': 9830 self.assertAlmostEqual(value, 1.08726698, 6) 9831 elif r2eff_estimate == 'chi2_pyt': 9832 self.assertAlmostEqual(value, 1.09708821, 6) 9833 elif model == MODEL_MP05: 9834 if r2eff_estimate == 'direct': 9835 self.assertAlmostEqual(value, 1.08837241, 6) 9836 elif r2eff_estimate == 'MC2000': 9837 self.assertAlmostEqual(value, 1.08726706, 6) 9838 elif r2eff_estimate == 'chi2_pyt': 9839 self.assertAlmostEqual(value, 1.09708832, 6) 9840 elif model == MODEL_NS_R1RHO_2SITE: 9841 if r2eff_estimate == 'direct': 9842 self.assertAlmostEqual(value, 1.56001812, 5) 9843 elif r2eff_estimate == 'MC2000': 9844 self.assertAlmostEqual(value, 1.55833321, 5) 9845 elif r2eff_estimate == 'chi2_pyt': 9846 self.assertAlmostEqual(value, 1.36406712, 5) 9847 9848 elif param == 'kex': 9849 if model == MODEL_DPL94: 9850 if r2eff_estimate == 'direct': 9851 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9852 elif r2eff_estimate == 'MC2000': 9853 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9854 elif r2eff_estimate == 'chi2_pyt': 9855 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9856 elif model == MODEL_TP02: 9857 if r2eff_estimate == 'direct': 9858 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9859 elif r2eff_estimate == 'MC2000': 9860 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9861 elif r2eff_estimate == 'chi2_pyt': 9862 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9863 elif model == MODEL_TAP03: 9864 if r2eff_estimate == 'direct': 9865 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9866 elif r2eff_estimate == 'MC2000': 9867 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9868 elif r2eff_estimate == 'chi2_pyt': 9869 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9870 elif model == MODEL_MP05: 9871 if r2eff_estimate == 'direct': 9872 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9873 elif r2eff_estimate == 'MC2000': 9874 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9875 elif r2eff_estimate == 'chi2_pyt': 9876 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9877 elif model == MODEL_NS_R1RHO_2SITE: 9878 if r2eff_estimate == 'direct': 9879 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9880 elif r2eff_estimate == 'MC2000': 9881 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9882 elif r2eff_estimate == 'chi2_pyt': 9883 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9884 9885 elif param == 'chi2': 9886 if model == MODEL_NOREX: 9887 if r2eff_estimate == 'direct': 9888 self.assertAlmostEqual(value, 848.42016907, 5) 9889 elif r2eff_estimate == 'MC2000': 9890 self.assertAlmostEqual(value, 3363.95829122, 5) 9891 elif r2eff_estimate == 'chi2_pyt': 9892 self.assertAlmostEqual(value, 5976.49946726, 5) 9893 elif model == MODEL_DPL94: 9894 if r2eff_estimate == 'direct': 9895 self.assertAlmostEqual(value, 179.47041241) 9896 elif r2eff_estimate == 'MC2000': 9897 self.assertAlmostEqual(value, 710.24767560) 9898 elif r2eff_estimate == 'chi2_pyt': 9899 self.assertAlmostEqual(value, 612.72616697, 5) 9900 elif model == MODEL_TP02: 9901 if r2eff_estimate == 'direct': 9902 self.assertAlmostEqual(value, 29.33882530, 6) 9903 elif r2eff_estimate == 'MC2000': 9904 self.assertAlmostEqual(value, 114.47142772, 6) 9905 elif r2eff_estimate == 'chi2_pyt': 9906 self.assertAlmostEqual(value, 250.50838162, 5) 9907 elif model == MODEL_TAP03: 9908 if r2eff_estimate == 'direct': 9909 self.assertAlmostEqual(value, 29.29050673, 6) 9910 elif r2eff_estimate == 'MC2000': 9911 self.assertAlmostEqual(value, 114.27987534) 9912 elif r2eff_estimate == 'chi2_pyt': 9913 self.assertAlmostEqual(value, 250.04050719, 5) 9914 elif model == MODEL_MP05: 9915 if r2eff_estimate == 'direct': 9916 self.assertAlmostEqual(value, 29.29054301, 6) 9917 elif r2eff_estimate == 'MC2000': 9918 self.assertAlmostEqual(value, 114.28002272) 9919 elif r2eff_estimate == 'chi2_pyt': 9920 self.assertAlmostEqual(value, 250.04077478, 5) 9921 elif model == MODEL_NS_R1RHO_2SITE: 9922 if r2eff_estimate == 'direct': 9923 self.assertAlmostEqual(value, 34.44010543, 6) 9924 elif r2eff_estimate == 'MC2000': 9925 self.assertAlmostEqual(value, 134.14368365) 9926 elif r2eff_estimate == 'chi2_pyt': 9927 self.assertAlmostEqual(value, 278.55121388, 5) 9928 9929 9930 # Print the final pipe. 9931 model = 'final' 9932 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9933 print("\nFinal pipe") 9934 9935 # Loop over the spins. 9936 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9937 # Generate spin string. 9938 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9939 9940 # Loop over the parameters. 9941 print("Optimised model for spin: %s" % (spin_string)) 9942 param = 'model' 9943 9944 # Get the value. 9945 value = getattr(cur_spin, param) 9946 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9947 9948 9949 ### Now check some of the written out files. 9950 file_names = ['r1rho_prime', 'r1'] 9951 9952 for file_name_i in file_names: 9953 9954 # Make the file name. 9955 file_name = "%s.out" % file_name_i 9956 9957 # Get the file path. 9958 file_path = get_file_path(file_name, result_dir_name + sep + model) 9959 9960 # Test the file exists. 9961 print("Testing file access to: %s"%file_path) 9962 self.assert_(access(file_path, F_OK)) 9963 9964 # Now open, and compare content, line by line. 9965 file_prod = open(file_path) 9966 lines_prod = file_prod.readlines() 9967 file_prod.close() 9968 9969 # Loop over the lines. 9970 for i, line in enumerate(lines_prod): 9971 # Make the string test 9972 line_split = line.split() 9973 9974 # Continue for comment lines. 9975 if line_split[0] == "#": 9976 print(line), 9977 continue 9978 9979 # Assign the split of the line. 9980 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9981 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9982 9983 if res_num == '52': 9984 # Assert that the value is not None. 9985 self.assertNotEqual(val, 'None')
9986